-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCeasarCipher.cpp
More file actions
49 lines (42 loc) · 1007 Bytes
/
CeasarCipher.cpp
File metadata and controls
49 lines (42 loc) · 1007 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
// problem: "https://www.hackerrank.com/challenges/caesar-cipher-1/problem"
#include<iostream>
using namespace std;
int main()
{
char string[100];
int i,size,K,x,y;
cin>>size;
cin>>string;
cin>>K;
for(i=0;i<size;i++)
{
if(isalpha(string[i]))
{
if(isupper(string[i]))
{
x=K%26;
if(x+(int)(string[i])<91)
cout<<(char)(x+(int)(string[i]));
else
{
y=x-(91-(int)(string[i]));
cout<<(char)(y+65);
}
}
else
{
x=K%26;
if(x+(int)(string[i])<123)
cout<<(char)(x+(int)(string[i]));
else
{
y=x-(123-(int)(string[i]));
cout<<(char)(y+97);
}
}
}
else
cout<<string[i];
}
return 0;
}