-
Notifications
You must be signed in to change notification settings - Fork 16
/
cipher(hacker earth problem)
56 lines (54 loc) · 1.47 KB
/
cipher(hacker earth problem)
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
#include<stdio.h>
int main()
{
char ch[100000];
int n,i,c;
scanf("%s",ch);
scanf("%d",&n);
for( i=0;ch[i];i++)
{
if(ch[i]>=48&&ch[i]<=57)
{ if(n>10)
{ c=n%10;
if(ch[i]+c<=57)
printf("%c",ch[i]+c);
else if(ch[i]+c>57)
printf("%c",(47+((ch[i]+c)-57)));
}
else if(ch[i]+n<=57)
printf("%c",ch[i]+n);
else if(ch[i]+c>57)
printf("%c",(47+((ch[i]+n)-57)));
}
else if(ch[i]>=65&&ch[i]<=90)
{ if(n>26)
{
c=n%26;
if(ch[i]+c<=90)
printf("%c",ch[i]+c);
else if(ch[i]+c>90)
printf("%c",(64+((ch[i]+c)-90)));
}
else if(ch[i]+n<=90)
printf("%c",ch[i]+n);
else if(ch[i]+n>90)
printf("%c",(64+((ch[i]+n)-90)));
}
else if(ch[i]>=97&&ch[i]<=122)
{ if(n>26)
{ c=n%26;
if(ch[i]+c<=122)
printf("%c",ch[i]+c);
else if(ch[i]+c>122)
printf("%c",(96+((ch[i]+c)-122)));
}
else if(ch[i]+n<=122)
printf("%c",ch[i]+n);
else if(ch[i]+n>122)
printf("%c",(96+((ch[i]+n)-122)));
}
else
printf("%c",ch[i]);
}
return 0;
}