Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. // dz16.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
  2. //
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. int isUpper(char a)
  10. {
  11.     int result = 0;
  12.     if (a >= 'A' && a <= 'z')
  13.         result = 1;
  14.  
  15.     return result;
  16. }
  17.  
  18. int isLower(char a)
  19. {
  20.     int result = 0;
  21.     if (a >= 'a' && a <= 'z')
  22.         result = 1;
  23.  
  24.     return result;
  25. }
  26.  
  27. int isNumber(char a)
  28. {
  29.     int result = 0;
  30.     if (a >= '0' && a <= '9')
  31.         result = 1;
  32.  
  33.     return result;
  34. }
  35.  
  36. char shifr(char a, int key)
  37. {
  38.     if (isUpper(a))
  39.     {
  40.         a += key;
  41.         if ((int)a > 90)
  42.         {
  43.             key = a - 90;
  44.             a = 65 + key - 1;
  45.         }
  46.     }
  47.     if (isLower(a))
  48.     {
  49.         a += key;
  50.         if ((int)a > 122)
  51.         {
  52.             key = a - 122;
  53.             a = 97 + key - 1;
  54.         }
  55.     }
  56.     if (isNumber(a))
  57.     {
  58.         a += key;
  59.         if ((int)a > 57)
  60.         {
  61.             key = a - 57;
  62.             a = 48 + key - 1;
  63.         }
  64.     }
  65.     return a;
  66. }
  67.  
  68.  
  69.  
  70.  
  71. int main()
  72. {
  73.  
  74.     string str; int k;
  75.     cout << "Enter string - "; getline(cin, str);
  76.     cout << "\nEnter key - "; cin >> k;
  77.  
  78.     for (int i = 0; i < str.length(); i++)
  79.     {
  80.         str[i] = shifr(str[i], k);
  81.     }
  82.  
  83.     for (int i = 0; i < str.length(); i++)
  84.     {
  85.         cout << str[i];
  86.     }
  87.  
  88.     //for (int i = 0; i < 255; i++)
  89.     //{
  90.     //  cout << i << " - " << (char)i << endl;
  91.     //}
  92.  
  93.     system("pause");
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement