forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcpc11f.cpp
44 lines (44 loc) · 1.05 KB
/
gcpc11f.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
// 2014-10-07
#include <cstdio>
#include <cstring>
int main() {
int c; scanf("%d\n", &c);
while (c--) {
char s[1111];
gets(s);
int l = strlen(s);
int cnt[256] = {0};
for (int i = 0; i < l; i++) {
cnt[s[i]]++;
}
int best = 0;
for (char c = 'A'; c <= 'Z'; c++) {
if (cnt[c] > best) {
best = cnt[c];
}
}
bool fail = false;
char bestchar = 0;
for (char c = 'A'; c <= 'Z'; c++) {
if (cnt[c] == best) {
if (bestchar == 0) {
bestchar = c;
} else {
fail = true;
}
}
}
if (fail) {
puts("NOT POSSIBLE");
continue;
}
int shift = (bestchar - 'E' + 26)%26;
for (int i = 0; i < l; i++) {
if (s[i] != ' ') {
s[i] = 'A' + (s[i] - 'A' - shift + 26)%26;
}
}
printf("%d %s\n", shift, s);
}
return 0;
}