题目

代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
string s1,s2;
int t,n;
ll has1[100005],has2[100005],pw[100005]={1};
ll geth(int l,int r){
return has1[r]-has1[l-1]*pw[r-l+1];
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
for(int i=1;i<=100000;i++){
pw[i]=pw[i-1]*26;
}
cin>>t;
while(t--){
map<char,char> mp;
cin>>s1>>s2;
for(int i=0;i<26;i++){
mp[s1[i]]='a'+i;
}
n=s2.size();
for(int i=1;i<=n;i++){
has1[i]=has1[i-1]*26+s2[i-1];
has2[i]=has2[i-1]*26+mp[s2[i-1]];
}
int anss=0;
for(int k=(n+1)/2;k<=n;k++){
if(has2[n-k]==geth(k+1,n)){
anss=k;
break;
}
}
for(int i=0;i<anss;i++){
cout<<s2[i];
}
for(int i=0;i<anss;i++){
cout<<mp[s2[i]];
}
cout<<"\n";
}
return 0;
}