-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaeser.cpp
More file actions
60 lines (60 loc) · 762 Bytes
/
caeser.cpp
File metadata and controls
60 lines (60 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
using namespace std;
int main(){
int n,k,i,t,flag;
cin>>n;
char s[n];
cin>>s;
cin>>k;
int a[n];
for(i=0;i<n;i++){
a[i]=(int)s[i];
}
for(i=0;i<n;i++){
if(a[i]>=65 && a[i]<=90){
if(a[i]+k>90){
t=a[i]+k-90;
if(t<=26)
a[i]=65+t-1;
else
{
do
{
t-=26;
if(t>26)
flag=1;
else
flag=0;
}while(flag!=0);
a[i]=65+t-1;
}
}
else
a[i]+=k;
}
if(a[i]>=97 && a[i]<=122){
if(a[i]+k>122){
t=a[i]+k-122;
if(t<=26)
a[i]=97+t-1;
else
{
do{
t-=26;
if(t>26)
flag=1;
else
flag=0;
}while(flag!=0);
a[i]=97+t-1;
}
}
else
a[i]+=k;
}
}
for(i=0;i<n;i++){
cout<<(char)a[i];
}
return 0;
}