Keypad typing

PROBLEM :

You are given N strings of alphabet characters and the task is to find their matching decimal representation as on the shown keypad. Output the decimal representation corresponding to the string. For ex: if you are given “amazon” then its corresponding decimal representation will be 262966.



Input:

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of a single line containing a string.

Output:

For each test case, print in a new line, the corresponding decimal representation of the given string.

Constraints:

1 = T = 100
1 = length of String = 100

Example:

Input
2
geeksforgeeks
geeksquiz

Output
4335736743357
433577849

--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

#include<iostream>
using namespace std;
#include<string.h>
int main()
 {
int t,l,i ;
char str[200] ;
cin>>t ;
while(t--)
{
   scanf(" %[^\n]s",str) ;
 
   l=strlen(str) ;
   for(i=0;i<l;i++)
   {
       if(str[i]>='a'&&str[i]<='c')
           cout<<2 ;
      else if(str[i]>='d'&&str[i]<='f')
           cout<<3 ;
      else if(str[i]>='g'&&str[i]<='i')
           cout<<4 ;
      else if(str[i]>='j'&&str[i]<='l')
           cout<<5 ;
      else if(str[i]>='m'&&str[i]<='o')
           cout<<6 ;
      else if(str[i]>='p'&&str[i]<='s')
           cout<<7 ;
      else if(str[i]>='t'&&str[i]<='v')
           cout<<8 ;
      else if(str[i]>='w'&&str[i]<='z')
           cout<<9 ;
   }
   cout<<endl ;
}
return 0;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )