做的心神崩溃,,,紫书上的题目描述是错的,,,然后uDuBug里的数据也是错的,,,,

害我傻傻的照着错的数据疯狂WA,直接心态崩掉了

ps:映射真好用

#include<bits/stdc++.h>
using namespace std;

string s,a[100010];
map<char,string>q;
map<string,string>p;
char ch;
int tot,len,t,r;
bool flag;

int main()
{
    tot = 0;
    while(1)
    {
        cin >> ch;
        if(ch == '*') break;
        cin >> s;
        q[ch] = s;
    }
    while(1)
    {
        cin >> s;
        if(s == "*") break;
        a[++tot] = s;
        len = a[tot].size();
        string ss = "";
        for(int i = 0;i < len; ++i) ss += q[a[tot][i]];
        p[a[tot]] = ss;
    }
    while(1)
    {
        cin >> s;
        if(s == "*") break;
        len = s.size();
        flag = 0;
        r = 0;
        t = 80;
        for(int i = 1;i <= tot; ++i)
        {
            if(p[a[i]] == s) if(!flag) cout << a[i],flag = 1;
            else
            {
                cout << '!';
                break;
            }
            else
            {
                int l = p[a[i]].size();
                bool f = 1;
                if(l != len && abs(l - len) < t)
                {
                    for(int j = 0;j < min(len,l); ++j)
                        if(p[a[i]][j] != s[j]) f = 0;
                    if(f) r = i,t = abs(l - len);
                }
            }
        }
        if(!flag) cout << a[r] << "?";
        cout << '\n';
    }
    return 0;
}