Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // dz16.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
- //
- #include <iostream>
- #include <string>
- using namespace std;
- int isUpper(char a)
- {
- int result = 0;
- if (a >= 'A' && a <= 'z')
- result = 1;
- return result;
- }
- int isLower(char a)
- {
- int result = 0;
- if (a >= 'a' && a <= 'z')
- result = 1;
- return result;
- }
- int isNumber(char a)
- {
- int result = 0;
- if (a >= '0' && a <= '9')
- result = 1;
- return result;
- }
- char shifr(char a, int key)
- {
- if (isUpper(a))
- {
- a += key;
- if ((int)a > 90)
- {
- key = a - 90;
- a = 65 + key - 1;
- }
- }
- if (isLower(a))
- {
- a += key;
- if ((int)a > 122)
- {
- key = a - 122;
- a = 97 + key - 1;
- }
- }
- if (isNumber(a))
- {
- a += key;
- if ((int)a > 57)
- {
- key = a - 57;
- a = 48 + key - 1;
- }
- }
- return a;
- }
- int main()
- {
- string str; int k;
- cout << "Enter string - "; getline(cin, str);
- cout << "\nEnter key - "; cin >> k;
- for (int i = 0; i < str.length(); i++)
- {
- str[i] = shifr(str[i], k);
- }
- for (int i = 0; i < str.length(); i++)
- {
- cout << str[i];
- }
- //for (int i = 0; i < 255; i++)
- //{
- // cout << i << " - " << (char)i << endl;
- //}
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement