forked from mintuhouse/spoj-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9122-gcpc11f.cpp
46 lines (45 loc) · 1.1 KB
/
9122-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
45
46
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main(){
int c;
string s;
char S[1001];
int n[26];
cin>>c;
getline(cin,s);
for(int i=0;i<c;i++){
for(int j=0;j<26;j++) n[j]=0;
getline(cin,s);
strcpy(S,s.c_str());
int sz=strlen(S);
for(int j=0;j<sz;j++){
if(S[j]!=' '){
n[(int)(S[j]-'A')]++;
}
}
//for(int j=0;j<26;j++) cout<<(char)(j+'A')<<" "<<n[j]<<endl;
int max=n[0], maxj=0;
for(int j=1;j<26;j++){
if(n[j]>max){
max=n[j];
maxj=j;
}else if(n[j]==max){
maxj=-1;
}
}
if(maxj==-1){
cout<<"NOT POSSIBLE"<<endl;
}else{
if(maxj-4<0)cout<<(maxj+22)<<" ";
else cout<<maxj-4<<" ";
for(int j=0;j<sz;j++){
if(S[j]==' ') cout<<' ';
else cout<<(char)((((unsigned int)(S[j]+(int)'A'-maxj+4))%26)+(int)'A');
}
cout<<endl;
}
}
return 0;
}