逆向思维
先将输入的字典翻译为数字
然后在按照输入的数字进行查找
用map
#include<iostream>
#include<map>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
map<char, char> dic;
map<string, vector<string>> ans;
void inti() {
int i, j;
char ap = 'A';
for (i = 2; i <= 9; i++) {
for (j = 0; j <= 2; j++) {
if (i == 7 && j == 1)ap++;
dic[char(ap + j)] = i + '0';
dic[char(ap + j + 32)] = i + '0';
}
ap += 3;
}
dic['Q'] = '0';
dic['q'] = '0';
dic['Z'] = '0';
dic['z'] = '0';
}
bool isvalid(string name) {
for (int i = 0; i < name.size(); i++) {
if (!((name[i] >= 'A' && name[i] <= 'Z') || (name[i] >= 'a' && name[i] <= 'z'))) {
return false;
}
}
return true;
}
int main() {
inti();
string name, num;
int i;
while (cin >> name && name != "#") {
num = "";
// if (!isvalid(name))continue;
for (i = 0; i < name.size(); i++) {
num += dic[name[i]];
}
ans[num].push_back(name);
}
map<string, vector<string>>::iterator it = ans.begin();
for (; it != ans.end(); it++) {
sort(it->second.begin(), it->second.end());
}
while (cin >> num) {
if (ans.find(num) != ans.end()) {
cout << ans[num][0];
for (i = 1; i < ans[num].size(); i++) {
cout << " " << ans[num][i];
}
} else {
printf("NONE");
}
printf("\n");
}
}