int cmp(string a, string b) { if (a == b) return0; if (a.size() > b.size()) a.swap(b); if (a == b.substr(0, a.size())) return b.size() - a.size(); return666; }
int main() { //freopen("in.txt", "r", stdin); //ios::sync_with_stdio(false); while ((cin >> c) && c != '*') cin >> morse[c]; while ((cin >> wo) && wo[0] != '*') { auto cp = wo.begin(); tran = morse[*cp]; while (++cp != wo.end()) tran += morse[*cp]; word[wo] = tran; } while ((cin >> tran) && tran[0] != '*') { result.clear(); intmin = 888; for (auto i = word.begin();i != word.end();++i) { if (i->second == tran)//精确寻找 if (!result.size() || *result.rbegin() == '?') result = i->first; else { result += "!";break; } elseif (!result.size() || *result.rbegin() == '?') {//模糊寻找 int n = cmp(tran, i->second); if (n<min) min = n, result = i->first + "?"; } } cout << result << '\n'; } return0; }