fork(1) download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4.  
  5. #define NO_LETTERS ('Z' - 'A' + 1)
  6.  
  7. using namespace std;
  8.  
  9. string rot(string s, int r)
  10. {
  11. for (int i = 0; i < s.size(); i++)
  12. {
  13. if (s[i] >= 'A' && s[i] <= 'Z')
  14. {
  15. s[i] = ((s[i] - 'A') + r) % NO_LETTERS + 'A';
  16. }
  17. else if (s[i] >= 'a' && s[i] <= 'z')
  18. {
  19. s[i] = ((s[i] - 'a') + r) % NO_LETTERS + 'a';
  20. }
  21. }
  22.  
  23. return s;
  24. }
  25.  
  26. int main()
  27. {
  28. int x, k;
  29. string tekst;
  30.  
  31. while (cin >> x >> k >> tekst)
  32. {
  33. if(x == 1)
  34. {
  35. cout << rot(tekst, k) << endl;
  36. }
  37. else
  38. {
  39. cout << rot(tekst, NO_LETTERS - k) << endl;
  40. }
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0s 3236KB
stdin
1 3 krwq_KRWQ+-KrWQ
0 3 nuzt_NUZT+-NuZT
stdout
nuzt_NUZT+-NuZT
krwq_KRWQ+-KrWQ