#include <bits/stdc++.h>
using namespace std;
int main(){
string t;
cin>>t;
int n=t.size();
string s1(n,‘a‘),s2(n,‘a‘),s3(n,‘a‘);
for(int i=0;i<n;i++){
s1[i]=char(‘a‘+(i%26));//从a到z循环
s2[i]=char(‘a‘+((i/26)%26));//第i位为(i/26)%26+‘a‘,保证了26*26内不会和s1相同
s3[i]=char(‘a‘+((i/26/26)%26));//保证了26^3内不会和s1相同,类似哈希编码
}
cout<<"? "<<s1<<endl;
string t1;
cin>>t1;
cout<<"? "<<s2<<endl;
string t2;
cin>>t2;
cout<<"? "<<s3<<endl;
string t3;
cin>>t3;
vector<int>p(n);
for(int i=0;i<n;i++)
p[i]=(t1[i]-‘a‘)+(t2[i]-‘a‘)*26+(t3[i]-‘a‘)*26*26;//将变化后的值根据编码还原
string s(n,‘a‘);
for(int i=0;i<n;i++)
s[p[i]]=t[i];//26^3>1000,所以可行
cout<<"! "<<s<<endl;
return 0;
}
原文地址:https://www.cnblogs.com/ldudxy/p/10486913.html
时间: 2024-11-01 10:49:51