problem id:--http://practice.geeksforgeeks.org/problems/keypad-typing/0
code:--
#include <stdio.h>
int main() {
int t,i;
char str[100];
scanf("%d ",&t);
while(t--)
{
scanf("%s ",str);
i=0;
while(str[i]!='\0')
{
switch(str[i])
{
case 'a':
case 'b':
case 'c': printf("2");
break;
case 'd':
case 'e':
case 'f':printf("3");
break;
case 'g':
case 'h':
case 'i':printf("4");
break;
case 'j':
case 'k':
case 'l':printf("5");
break;
case 'm':
case 'n':
case 'o':printf("6");
break;
case 'p':
case 'q':
case 'r':
case 's':printf("7");
break;
case 't':
case 'u':
case 'v':printf("8");
break;
case 'w':
case 'x':
case 'y':
case 'z':printf("9");
break;
}
i++;
}
printf("\n");
}
return 0;
}
code:--
#include <stdio.h>
int main() {
int t,i;
char str[100];
scanf("%d ",&t);
while(t--)
{
scanf("%s ",str);
i=0;
while(str[i]!='\0')
{
switch(str[i])
{
case 'a':
case 'b':
case 'c': printf("2");
break;
case 'd':
case 'e':
case 'f':printf("3");
break;
case 'g':
case 'h':
case 'i':printf("4");
break;
case 'j':
case 'k':
case 'l':printf("5");
break;
case 'm':
case 'n':
case 'o':printf("6");
break;
case 'p':
case 'q':
case 'r':
case 's':printf("7");
break;
case 't':
case 'u':
case 'v':printf("8");
break;
case 'w':
case 'x':
case 'y':
case 'z':printf("9");
break;
}
i++;
}
printf("\n");
}
return 0;
}
No comments:
Post a Comment