Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string shifr(string a, int key)
- {
- for (int i = 0; i < a.length(); i++)
- {
- if ((a[i] >= 'A' && a[i] <= 'Z'))
- {
- a[i] = (a[i] - 'A' + key) % 26 + 'A' ;
- }
- if ((a[i] >= 'a' && a[i] <= 'z'))
- {
- a[i] = (a[i] - 'a' + key) % 26 + 'a';
- }
- if ((a[i] >= '0' && a[i] <= '9'))
- {
- a[i] = (a[i] - '0' + key) % 10 + '0';
- }
- }
- return a;
- }
- int main()
- {
- string str; int k;
- cout << "Enter string - "; getline(cin, str);
- cout << "\nEnter key - "; cin >> k;
- str = shifr(str, k);
- cout << '\n' << str;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement