forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwscipher.cpp
60 lines (60 loc) · 841 Bytes
/
wscipher.cpp
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
// 2008-08-21
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int k1,k2,k3,N,i,j,cnt;
char s[100];
char s2[100];
for(;;)
{
scanf("%d %d %d",&k1,&k2,&k3);
if (!(k1|k2|k3))
return 0;
scanf("%s",s);
N=strlen(s);
s2[N]=0;
for (i=0; i<N; i++)
{
if (s[i]>='a'&&s[i]<='i')
{
j=i;
cnt=0;
while (cnt<k1)
{
j=(j+1)%N;
if (s[j]>='a'&&s[j]<='i')
cnt++;
}
s2[j]=s[i];
}
else if (s[i]>='j'&&s[i]<='r')
{
j=i;
cnt=0;
while (cnt<k2)
{
j=(j+1)%N;
if (s[j]>='j'&&s[j]<='r')
cnt++;
}
s2[j]=s[i];
}
else
{
j=i;
cnt=0;
while (cnt<k3)
{
j=(j+1)%N;
if (s[j]>='s'&&s[j]<='z'||s[j]=='_')
cnt++;
}
s2[j]=s[i];
}
}
printf("%s\n",s2);
}
}