Advertisement
Guest User

CaesarQWERTY 1.1

a guest
Nov 14th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <stdio.h>
  5. #include <string>
  6.  
  7. #define ll long long
  8.  
  9. using namespace std;
  10.  
  11. map <char, ll> letter;
  12. string qwerty = "qwertyuiopasdfghjklzxcvbnm";
  13. string s;
  14. ll shift;
  15.  
  16. void mapping() {
  17.     for (ll i = 0; i < 26; i++) {
  18.         letter[qwerty[i]] = i;
  19.     }
  20. }
  21.  
  22. char transformation(char a, ll cshift) {
  23.     if (cshift == 0) return a;
  24.     ll index = letter[a];
  25.     if (cshift < 0) index += 26;
  26.     return qwerty[index + cshift % 26];
  27. }
  28.  
  29. int main() {
  30.     //in input file you should write text on the next line after the shift number
  31.     //you can write text on several lines
  32.     //shift number should be in [-4 * 1e18, 4 * 1e18]
  33.     //freopen("inputfilename", "r", stdin);
  34.     //freopen("outputfilename", "w", stdout);
  35.     qwerty += qwerty;
  36.     mapping();
  37.     cin >> shift;
  38.     getline(cin, s);
  39.     while (getline(cin, s)){
  40.         for (auto i : s) {
  41.             if (i >= 'A' && i <= 'Z') {
  42.                 cout << toupper(transformation(tolower(i), shift));
  43.             } else if (i >= 'a' && i <= 'z') {
  44.                 cout << transformation(i, shift);
  45.             } else {
  46.                 cout << i;
  47.             }
  48.         }
  49.         cout << '\n';
  50.     }
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement