UVa 10921 Find the Telephone
1
#include <stdio.h>
2 #include
<stdlib.h>
3 #include
<algorithm>
4 #include
<iostream>
5 using
namespace std;
6 int main()
7 {
8 string str;
9 while(cin>>str)
10 {
11 int len=str.length();
12 string ans="";
13 for(int i=0;i<len;i++)
14 {
15 if(str[i]>='A' && str[i]<='C') ans+='2';
16 else if(str[i]>='D' && str[i]<='F') ans+='3';
17 else if(str[i]>='G' && str[i]<='I') ans+='4';
18 else if(str[i]>='J' && str[i]<='L') ans+='5';
19 else if(str[i]>='M' && str[i]<='O') ans+='6';
20 else if(str[i]>='P' && str[i]<='S') ans+='7';
21 else if(str[i]>='T' && str[i]<='V') ans+='8';
22 else if(str[i]>='W' && str[i]<='Z') ans+='9';
23 else ans+=str[i];
24 }
25 cout<<ans<<endl;
26 }
27
28
29 return 0;
30 }
留言
張貼留言