Advertisement
MeehoweCK

Untitled

Nov 9th, 2020
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string typ;
  9.     int oile;
  10.     bool czymale;
  11.     string a;
  12.     cin>>typ;
  13.     cin>>oile;
  14.     cin.ignore();
  15.  
  16.     getline(cin,a);
  17.  
  18.     oile=oile%26;
  19.  
  20.     int rozmiar = a.size();
  21.  
  22.     int nr_znaku;
  23.  
  24.     if(typ=="szyfruj")
  25.     {
  26.         for(int x=0; x<rozmiar; x++)
  27.         {
  28.             if(a[x]<=122&&a[x]>=97)
  29.             {
  30.                 czymale=true;
  31.             }
  32.             else
  33.             {
  34.                 czymale=false;
  35.             }
  36.             if((a[x]<=90&&a[x]>=65)||(a[x]<=122&&a[x]>=97))
  37.             {
  38.                 nr_znaku = static_cast<int>(a[x]) + oile;
  39.                
  40.                 if((czymale && nr_znaku > 122) || (!czymale && nr_znaku > 90))
  41.                     nr_znaku -= 36;
  42.  
  43.                 a[x] = static_cast<char>(nr_znaku);
  44.             }
  45.         }
  46.     }
  47.     else if(typ=="odszyfruj")
  48.     {
  49.         for(int x=0; x<rozmiar; x++)
  50.         {
  51.             if(a[x]<=122&&a[x]>=97)
  52.             {
  53.                 czymale=true;
  54.             }
  55.             else
  56.             {
  57.                 czymale=false;
  58.             }
  59.             if((a[x]<=90&&a[x]>=65)||(a[x]<=122&&a[x]>=97))
  60.             {
  61.                 a[x]=a[x]-oile;
  62.  
  63.                 if(czymale==false&&a[x]<65)
  64.                 {
  65.                     a[x]=91-(65-a[x]);
  66.                 }
  67.                 else if(czymale==true&&a[x]<97)
  68.                 {
  69.                     a[x]=123-(97-a[x]);
  70.                 }
  71.             }
  72.         }
  73.     }
  74.  
  75.     cout <<a;
  76.  
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement