Solution of 10921 - Find the Telephone

Problem Description
source:https://uva.onlinejudge.org/external/109/10921.html

In some places is common to remember a phone number associating its digits to letters. In this way the expression “MY LOVE” means 69 5683. Of course there are some problems, because some phone numbers can not form a word or a phrase and the digits 1 and 0 are not associated to any letter. Your task is to read an expression and find the corresponding phone number based on the table below. An expression is composed by the capital letters (A-Z), hyphens (-) and the numbers 1 and 0.



Input 

The input consists of a set of expressions. Each expression is in a line by itself and has C characters, where 1 ≤ C ≤ 30. The input is terminated by enf of file (EOF). 

Output 

For each expression you should print the corresponding phone number. 

Sample Input 

1-HOME-SWEET-HOME 
MY-MISERABLE-JOB 

Sample Output 

1-4663-79338-4663 
69-647372253-562 

Solution:
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <string>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

int main()
{
    char c[40];
    int i;
    while(gets(c))
    {
        for(i=0;c[i]!='\0';i++)
        {
            if(c[i]=='A'||c[i]=='B'||c[i]=='C')
                printf("2");
            else if(c[i]=='D'||c[i]=='E'||c[i]=='F')
                printf("3");
            else if(c[i]=='G'||c[i]=='H'||c[i]=='I')
                printf("4");
            else if(c[i]=='J'||c[i]=='K'||c[i]=='L')
                printf("5");
            else if(c[i]=='M'||c[i]=='N'||c[i]=='O')
                printf("6");
            else if(c[i]=='P'||c[i]=='Q'||c[i]=='R'||c[i]=='S')
                printf("7");
            else if(c[i]=='T'||c[i]=='U'||c[i]=='V')
                printf("8");
            else if(c[i]=='W'||c[i]=='X'||c[i]=='Y'||c[i]=='Z')
                printf("9");
            else
                printf("%c",c[i]);
        }
        printf("\n");
    }
    return 0;
}

No comments:

Post a Comment

Write your comment - Share Knowledge and Experience