首页 > 代码库 > Name That Number

Name That Number

链接

分析:找出每一个字母对应的数字,然后看字典里面那个与其匹配

技术分享
 1 /*
 2 ID: ****
 3 PROG: namenum
 4 LANG: C++
 5 */
 6 #include<iostream>
 7 #include<fstream>
 8 #include<string.h>
 9  
10 using namespace std;
11  
12 const char alpha[26]={2,2,2,3,3,3,4,4,4,5,5,5, 6,6,6,7,0,7,7,8,8,8,9,9,9,0};
13 string data,tmp,words;
14 bool flag=false;
15  
16 int main(){
17     ifstream fin("namenum.in");
18     ofstream fout("namenum.out");
19     fin>>data;
20     ifstream tin("dict.txt");
21     while (tin>>words){
22           int l=words.size();
23           tmp="";
24           for (int i=0;i<l;i++) tmp+=alpha[words[i]-65];
25           if (tmp==data) {fout<<words<<endl;flag=true;}
26           }
27     if (!flag) fout<<"NONE"<<endl;
28     return 0;
29 }                                                                                           
View Code

 

Name That Number