这道题还是可以说是比较简单的,一开始是准备将输入的数字转换的名称全部保存下来,再将这些名称在字典中查找,毫无疑问,这样子太麻烦了,于是就换了一种思路,将字典的名称转换成数字与输入的数字比较,其中还需要注意一层层的筛选。代码如下。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int namesearch(char c){
int x=c-'A';
if (x>'Q'-'A'){
x--;
}
int num=(x/3)+2;
return num;
}
int main (){
freopen ("namenum.in","r",stdin);
string s;
cin>>s;
int l=s.length();
int i=0,cnt=0;
char ss[20],dic[5000][20];
bool judge=true,flag=false;
string dict;
freopen ("dict.txt","r",stdin);
freopen ("dict.out","w",stdout);
while(scanf("%s",ss)!=EOF){
dict=ss;
if (dict.length()!=l){
continue;
}
else {
judge=true;
for (i=0;i<l;i++){
if (namesearch(dict[i])!=(s[i]-'0')){
judge=false;
}
}
if (judge){
cout<<dict<<endl;
flag=true;
}
}
}
if (!flag){
cout<<"NONE";
}
return 0;
}