forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1009Enigma.cpp
More file actions
51 lines (48 loc) · 1.33 KB
/
1009Enigma.cpp
File metadata and controls
51 lines (48 loc) · 1.33 KB
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
//ZJU 1009 Enigma
//2003.09.05 BY ADAI
#include <iostream>
#include <cstring>
using namespace std;
int main(void){
int i,j,m,n,kase=0,t,p,q;
int change[3][26];
char temp[100000];
int convert[3];
while(cin>>m&&m!=0){
if(kase) cout<<endl;
cout<<"Enigma "<<++kase<<":"<<endl;
for(i=0;i<3;i++){
cin>>temp;
for(j=0;j<m;j++) change[i][temp[j]-'A']=j-(temp[j]-'A');
}
cin>>n;
while(n--){
cin>>temp;
convert[0]=convert[1]=convert[2]=0;
int length=strlen(temp);
for(i=0;i<length;i++){
/*convert[0]=i%m;
convert[1]=(i/m)%m;
convert[2]=(i/(m*m))%m;*/
t=temp[i]-'A';
for(p=2;p>=0;p--){
t+=change[p][(t-convert[p]+m)%m];
t=(t+m)%m;
}
cout<<char(t+'a');
convert[0]++;
if(convert[0]%m==0){
convert[0]=0;
convert[1]++;
if(convert[1]%m==0){
convert[1]=0;
convert[2]++;
if(convert[2]%m==0) convert[2]=0;
}
}
}
cout<<endl;
}
}
return 0;
}