/* ID: m1590291 TASK: namenum LANG: C++ */ /****************************************************************************************************************** 一个字母只对应一个数字,从字典中读入一个单词,把它转化成唯一对应的数字, 看它是否与给出的数字匹配, 时间规模是5000*12=6e4,空间规模是常数,而且编程复杂度较低 还可以先比较字符长度和数字长度,如果相等,逐位比较。 ******************************************************************************************************************/ #include <iostream> #include <fstream> #include <string.h> using namespace std; string dict[5000],f[5000]; void fuc() { char set[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'}; ifstream FIN("dict.txt"); for(int i=0;i<4617;i++){ FIN>>dict[i]; f[i]=dict[i]; } for(int i=0;i<4617;i++){ for(int j=0;j<dict[i].size();j++) f[i][j]=set[f[i][j]-'A']; } FIN.close(); } int main() { string s; ifstream fin("namenum.in"); ofstream fout("namenum.out"); fuc(); while(fin>>s) { int flag=0; for(int i=0;i<4617;i++) if(s == f[i]){ fout<<dict[i]<<endl; flag=1; } if(!flag) fout<<"NONE"<<endl; } fin.close(); fout.close(); return 0; }