-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathZOJ1006(AC).cpp
93 lines (87 loc) · 1.01 KB
/
ZOJ1006(AC).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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
using namespace std;
char get_char(const int i)
{
if(i == 0)
{
return '_';
}
else if(i >= 1 && i <= 26)
{
return 'a' + i - 1;
}
else if(i == 27)
{
return '.';
}
else
{
return EOF;
}
}
int get_code(const char ch)
{
if(ch == '_')
{
return 0;
}
else if(ch >= 'a' && ch <= 'z')
{
return ch + 1 - 'a';
}
else if(ch == '.')
{
return 27;
}
else
{
return -1;
}
}
int main()
{
int cc[100];
int pc[100];
int p_c[100];
int c_p[100];
char cs[200];
char ps[200];
int k;
int i;
int n;
while(1)
{
scanf("%d", &k);
if(k == 0)
{
break;
}
scanf("%s", cs);
n = strlen(cs);
for(i = 0; i < n; i++)
{
cc[i] = get_code(cs[i]);
}
for(i = 0; i < n; i++)
{
c_p[i] = k * i % n;
}
for(i = 0; i < n; i++)
{
p_c[c_p[i]] = i;
}
for(i = 0; i < n; i++)
{
pc[c_p[i]] = (cc[i] + i) % 28;
}
for(i = 0; i < n; i++)
{
ps[i] = get_char(pc[i]);
}
ps[n] = 0;
puts(ps);
}
return 0;
}