hack wa了,求调
查看原帖
hack wa了,求调
1004463
RoamingDuck楼主2024/7/4 17:01
#include <iostream>
#include <string>
#define ll long long
#define MAXN 3000060
using namespace std;
ll trie[MAXN][30];
ll word[MAXN];
ll vis[MAXN];
ll n, m;
string str;
ll tot;
ll res;
void push(string k)
{
    ll now = 0;
    for (ll i = 0; k[i]; i++)
    {
        ll a = k[i] - 'a';
        if (trie[now][a] == 0)
        {
            trie[now][a] = ++tot;
        }
        now = trie[now][a];
    }
    word[now]++;
    return;
}
ll query(string k)
{
    ll now = 0;
    for (ll i = 0; k[i]; i++)
    {
        ll a = k[i] - 'a';
        if (trie[now][a] == 0)
        {
            return -1;
        }
        now = trie[now][a];
    }
    return vis[now]++;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    while (n--)
    {
        cin >> str;
        push(str);
    }
    cin >> m;
    while (m--)
    {
        cin >> str;
        res = query(str);
        if (res == -1)
        {
            cout << "WRONG\n";
        }
        else if (res == 0)
        {
            cout << "OK\n";
        }
        else
        {
            cout << "REPEAT\n";
        }
    }
    return 0;
}
2024/7/4 17:01
加载中...