Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string typ;
- int oile;
- bool czymale;
- string a;
- cin>>typ;
- cin>>oile;
- cin.ignore();
- getline(cin,a);
- oile=oile%26;
- int rozmiar = a.size();
- int nr_znaku;
- if(typ=="szyfruj")
- {
- for(int x=0; x<rozmiar; x++)
- {
- if(a[x]<=122&&a[x]>=97)
- {
- czymale=true;
- }
- else
- {
- czymale=false;
- }
- if((a[x]<=90&&a[x]>=65)||(a[x]<=122&&a[x]>=97))
- {
- nr_znaku = static_cast<int>(a[x]) + oile;
- if((czymale && nr_znaku > 122) || (!czymale && nr_znaku > 90))
- nr_znaku -= 36;
- a[x] = static_cast<char>(nr_znaku);
- }
- }
- }
- else if(typ=="odszyfruj")
- {
- for(int x=0; x<rozmiar; x++)
- {
- if(a[x]<=122&&a[x]>=97)
- {
- czymale=true;
- }
- else
- {
- czymale=false;
- }
- if((a[x]<=90&&a[x]>=65)||(a[x]<=122&&a[x]>=97))
- {
- a[x]=a[x]-oile;
- if(czymale==false&&a[x]<65)
- {
- a[x]=91-(65-a[x]);
- }
- else if(czymale==true&&a[x]<97)
- {
- a[x]=123-(97-a[x]);
- }
- }
- }
- }
- cout <<a;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement