https://ac.nowcoder.com/acm/contest/329/J

题解:

std

#include <bits/stdc++.h>
using namespace std;
 
int p,q,r,t;
const int mod=9983;
int mul[3];
int in_dex[26];
int get_hash(char* s)//�±��1��ʼ
{
    int ans=0,len=strlen(s+1);
    for (int i=1;i<=len;i++)ans=(ans*mul[i%3] + in_dex[s[i]-'a'])%mod;
    return ans;
}
 
vector<string> ans[9983];
char s[100005];
 
int main()
{
    scanf("%d%d%d%d",&p,&q,&r,&t);
    mul[0]=p;mul[1]=q;mul[2]=r;
    for (int i=0;i<26;i++)in_dex[i]=i*t+t;
    for (int i1=1;i1<=26;i1++)
    {
        s[1]='a'+i1-1;
        for (int i2=0;i2<=26;i2++)
        {
            s[2]=i2?'a'+i2-1:0;
            for (int i3=0;i3<=26;i3++)
            {
                if (i2==0) break;
                s[3]=i3?'a'+i3-1:0;
                for (int i4=0;i4<=26;i4++)
                {
                    if (i3==0) break;
                    s[4]=i4?'a'+i4-1:0;
                    ans[get_hash(s)].emplace_back(s+1);
                }
            }
        }
    }
    int T;
    scanf("%d",&T);
    while (T--)
    {
        scanf("%s",s+1);
        bool flag=false;
        for (auto &i:ans[get_hash(s)])
            if (s+1!=i)
            {
                cout<<i<<endl;
                flag=true;
                break;
            }
        assert(flag);
    }
    return 0;
}