-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCIPHERJ.cpp
More file actions
55 lines (55 loc) · 830 Bytes
/
CIPHERJ.cpp
File metadata and controls
55 lines (55 loc) · 830 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
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <cstdlib>
using namespace std;
int main()
{
int n;
while(1)
{
scanf("%d",&n);
if(n==0)
break;
int a[n+5];
int i,j,k,count=1;
int res[210][210];
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
res[0][i]=i;
}
for(i=1;i<=n;i++)
{
count=1;
j=i;
while(a[j]!=i)
{
res[count++][i]=a[j];
j=a[j];
}
res[209][i]=count;
}
while(1)
{
scanf("%d",&k);
if(k==0)
break;
char *word;
word=(char *)calloc(210,sizeof(char));
char *final=(char *)calloc(210,sizeof(char));
fflush(stdin);
gets(word);
int count,pos;
for(i=1;i<=n;i++)
{
pos=res[k%res[209][i]][i];
final[pos-1]=word[i]==0?32:word[i];
}
for(j=0;j<n;j++)
printf("%c",final[j]);
printf("\n");
}
}
return 0;
}