Advertisement
MeehoweCK

Untitled

Nov 9th, 2020
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 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.                 //a[x]=a[x]+oile;
  39.                 nr_znaku = static_cast<int>(a[x]) + oile;
  40.  
  41.                 if(czymale==false&&a[x]>90)
  42.                 {
  43.                     a[x]=64+(a[x]-90);
  44.                 }
  45.                 else if(czymale==true&& nr_znaku >122)
  46.                 {
  47.                     nr_znaku=96+(nr_znaku-122);
  48.                     a[x] = static_cast<char>(nr_znaku);
  49.                 }
  50.             }
  51.         }
  52.     }
  53.     else if(typ=="odszyfruj")
  54.     {
  55.         for(int x=0; x<rozmiar; x++)
  56.         {
  57.             if(a[x]<=122&&a[x]>=97)
  58.             {
  59.                 czymale=true;
  60.             }
  61.             else
  62.             {
  63.                 czymale=false;
  64.             }
  65.             if((a[x]<=90&&a[x]>=65)||(a[x]<=122&&a[x]>=97))
  66.             {
  67.                 a[x]=a[x]-oile;
  68.  
  69.                 if(czymale==false&&a[x]<65)
  70.                 {
  71.                     a[x]=91-(65-a[x]);
  72.                 }
  73.                 else if(czymale==true&&a[x]<97)
  74.                 {
  75.                     a[x]=123-(97-a[x]);
  76.                 }
  77.             }
  78.         }
  79.     }
  80.  
  81.     cout <<a;
  82.  
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement