• Source
    1. #include <iostream>
    2. #include <string>
    3. #include <math.h>
    4. using namespace std;
    5.  
    6. int AT[200];
    7.  
    8. void init ()
    9. {
    10. for (int i=0; i<=200; i++)
    11. AT[i]=0;
    12. }
    13.  
    14. int main ()
    15. {
    16. int n;
    17. cin>>n;
    18. string xau;
    19. cin.ignore();
    20. for (int k=1; k<=n; k++)
    21. {
    22. getline (cin, xau);
    23. init ();
    24. int CMax = 0;
    25. for (int i=0; i<xau.length(); i++)
    26. {
    27. if (xau[i]>='A' && xau[i]<='Z')
    28. {
    29. int x = xau[i] - 0;
    30. AT[x]++;
    31. CMax = max (AT[x], CMax);
    32. }
    33. }
    34.  
    35. int count=0;
    36. char tmp;
    37. for (int i=0; i<=125; i++)
    38. {
    39. if (AT[i]==CMax)
    40. {
    41. tmp = i + 0;
    42. count++;
    43. if (count>1) break;
    44. }
    45. }
    46. if (count!=1) cout<<"NOT POSSIBLE"<<endl;
    47. else
    48. {
    49. int d;
    50. if (tmp>='E' && tmp<='Z')
    51. d = tmp - 'E';
    52. else if (tmp>='A' && tmp <'E')
    53. d = 5 - ('E' - tmp) + 21;
    54. cout<<d<<" ";
    55. for (int i=0; i<xau.size(); i++)
    56. {
    57. if (xau[i]>='A' && xau[i]<='Z')
    58. {
    59. int tmp_move = xau[i] - d;
    60. if (tmp_move >= 65)
    61. {
    62. char c = tmp_move;
    63. cout<<c;
    64. }
    65. else
    66. {
    67. tmp_move = 65 - tmp_move;
    68. char c = 91 - tmp_move;
    69. cout<<c;
    70. }
    71. }
    72. else
    73. cout<<' ';
    74. }
    75. cout<<endl;
    76. }
    77. }
    78. return 0;
    79. }