Sunday, May 1, 2016

UVA problem 10921 - Find the Telephone

Problem link (Click here)

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

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

    return 0;
}

No comments:

Post a Comment