题目:编码翻译,有些字母有对应的数字,有的没有,如果连续对应的数字相同只输出一个。
1 #include <iostream> 2 #include <cstdlib> 3 #include <cstdio> 4 using namespace std; 5 6 int rep( char c ) 7 { 8 switch( c ) { 9 case ‘B‘: 10 case ‘F‘: 11 case ‘P‘: 12 case ‘V‘: return 1; 13 case ‘C‘: 14 case ‘G‘: 15 case ‘J‘: 16 case ‘K‘: 17 case ‘Q‘: 18 case ‘S‘: 19 case ‘X‘: 20 case ‘Z‘: return 2; 21 case ‘D‘: 22 case ‘T‘: return 3; 23 case ‘L‘: return 4; 24 case ‘M‘: 25 case ‘N‘: return 5; 26 case ‘R‘: return 6; 27 default : return 0; 28 } 29 } 30 31 int main() 32 { 33 char temp[25]; 34 while(cin >> temp) 35 { 36 for(int i=0; temp[i]; ++i) 37 { 38 if(i>0 && rep(temp[i]) == rep(temp[i-1])) continue; 39 if(!rep(temp[i])) continue; 40 cout << rep(temp[i]); 41 } 42 cout << endl; 43 } 44 return 0; 45 }
原文:http://www.cnblogs.com/aze-003/p/5097263.html