fork(2) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <string>
  5. using namespace std;
  6.  
  7. class cipher{
  8. public:
  9. char letter;
  10. int frequency;
  11. };
  12. bool comp(const cipher &A,const cipher &B){
  13. if(A.frequency<B.frequency)
  14. return true;
  15. else
  16. return false;
  17. }
  18. vector<cipher> cipherF;
  19. int posOf(char c)
  20. {
  21. int i;
  22. for(i=0;i<26;++i)
  23. if(cipherF[i].letter == c)
  24. return i;
  25. return -1;
  26.  
  27.  
  28. }
  29. int main()
  30. {
  31.  
  32. int t;
  33. cin>>t;
  34. string tmp;
  35. getline(cin,tmp);
  36. while(t--){
  37. cipherF.clear();
  38. for(int i=97;i<=122;++i)
  39. {
  40. cipher cip;
  41. cip.letter = i;
  42. cip.frequency = 0;
  43. cipherF.push_back(cip);
  44.  
  45. }
  46. string txtF,cipherText;
  47. getline(cin,txtF);
  48. getline(cin,cipherText);
  49.  
  50. for(int i=0;i<cipherText.size();++i)
  51. {
  52. char c = tolower(cipherText[i]);
  53. ++(cipherF[c-97].frequency);
  54. }
  55.  
  56. stable_sort(cipherF.begin(),cipherF.end(),comp);
  57. for(int i=0;i<cipherText.size();++i)
  58. {
  59. int pos = posOf(cipherText[i]);
  60. if(pos == -1)
  61. continue;
  62. else if(isupper(cipherText[i]))
  63. cipherText[i] = toupper(txtF[pos]);
  64. else
  65. cipherText[i] = txtF[pos];
  66.  
  67.  
  68. }
  69. cout<<cipherText<<endl;
  70.  
  71.  
  72.  
  73. }
  74. }
  75.  
Runtime error #stdin #stdout 0s 3480KB
stdin
3
qwrtyuipasdfgjkzxcvbnmheol
dummy!
bfgjklmopqrstuwxzhvnicdyea
abcd b efgd hbi!
qwrtyuipasdfgjkzxcvbnmheol
Dummy!
stdout
Standard output is empty