MeehoweCK

Untitled

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