fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. string mode;
  7. string text;
  8. int k;
  9.  
  10. cin >> mode;
  11. cin >> k;
  12. cin.ignore();
  13. getline(cin, text);
  14.  
  15. for (int i = 0; i < text.size(); i++) {
  16. char c = text[i];
  17.  
  18. if (c >= 'A' && c <= 'Z') {
  19. if (mode == "szyfruj")
  20. text[i] = 'A' + (c - 'A' + k) % 26;
  21. else
  22. text[i] = 'A' + (c - 'A' - k) % 26;
  23. }
  24. else if (c >= 'a' && c <= 'z') {
  25. if (mode == "szyfruj")
  26. text[i] = 'a' + (c - 'a' + k) % 26;
  27. else
  28. text[i] = 'a' + (c - 'a' - k + 26) % 26;
  29. }
  30.  
  31. }
  32.  
  33. cout << text << endl;
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5320KB
stdin
szyfruj
5
Szyfr Cezara - jest skuteczny!
stdout
Xedkw Hjefwf - ojxy xpzyjhesd!