fork download
  1. #include<iostream>
  2. #include<queue>
  3. #include<algorithm>
  4. #include<list>
  5. #include<map>
  6. #include<vector>
  7. #include<string>
  8. #include<cstring>
  9. #include<cstdlib>
  10. #include<cstdio>
  11. using namespace std;
  12. #define Author "DemoVersion"
  13. #define MAXN -
  14. #define ull unsigned long long
  15. const int inf (3<<30);
  16. char chmap[255];
  17. bool isadd[255];
  18. void en(string &str){
  19. for(int i=0;i<str.length();i++)
  20. str[i]=chmap[str[i]];
  21. }
  22. int main()
  23. {
  24. map<string,bool> m;
  25. int i,T,N;
  26.  
  27. string text,key,tmp,ftmp,finals;
  28. cin>>T;
  29. while(T--){
  30. m.clear();
  31. cin>>N>>text>>key;
  32. for(i=0;i<255;i++)isadd[i]=false;
  33. for(i=0;i<26;i++)chmap['a'+i]=key[i];
  34. tmp="";
  35. for(i=0;i<text.length();i++){
  36. if(isadd[text[i]]==0){
  37. isadd[text[i]]=1;
  38. tmp+=text[i];
  39. }
  40. }
  41. ftmp=tmp;
  42. m[tmp]=true;
  43. while(1){
  44. en(tmp);
  45. if(m.count(tmp)>0)break;
  46. m[tmp]=true;
  47. }
  48. finals=m.begin()->first;
  49. for(int i=0;i<ftmp.length();i++)
  50. chmap[ftmp[i]]=finals[i];
  51. for(i=0;i<text.length();i++)
  52. text[i]=chmap[text[i]];
  53. cout<<text<<endl;
  54. }
  55. return 0;
  56. }
Success #stdin #stdout 0s 3480KB
stdin
3
7
pumiuau
xmurpwelifsobdhqkcajtzngvy
29
yzqjxynzysyrmttbjaymyrgyisvno
zcdefghijkamnopqrstulwxybv
24
bezmnftheuecthepegucagtz
cbafedihglkjonmrqputsxwvzy
stdout
acmicpc
ahlekashanamroozegarambadnist
beyondtheseathereisacity