UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#190953#3390. 凯撒密码Guoziyu1001ms1268kbC++993b2023-10-07 19:19:582023-10-07 21:41:56

answer

#include<bits/stdc++.h> 
using namespace std;
string a,b; int len,num1,num2;
bool opta,optb; int c;
int main(){
	cin >> a >> b; num1 = num2 = -1;
	len = a.size();
	for(int i = 0;i < len;i++){
		opta = optb = 0;
		if('a' <= a[i] && a[i] <= 'z'){
			opta = true;
		}
		if('a' <= b[i] && b[i] <= 'z'){
			optb = true;
		}
		if(opta != optb){
			cout << "IMPOSSIBLE";
			return 0;
		}
		if(a[i] <= b[i]){
			c = b[i] - a[i];
		}else{
			if(opta == 1){
				c = b[i] - a[i] + 26; 
			}else{
				c = b[i] - a[i] + 10; 
			}
		}
		if(opta && num1 != -1 && num1 != c){
			cout << "IMPOSSIBLE"; return 0;
		}
		if(!opta && num2 != -1 && num2 != c){
			cout << "IMPOSSIBLE"; return 0;
		}
		if(opta && num1 == -1) num1 = c;
		if(!opta && num2 == -1) num2 = c;
	} int x = 0;
	if(num1 == -1){cout << num2; return 0;}
	if(num2 == -1){cout << num1; return 0;}
	while(1){if((x * 26 + num1 - num2) % 10 == 0){
			cout << x * 26 + num1; break;
		}x++;
	}
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1184kb

input:

a
0

output:

IMPOSSIBLE

result:

ok single line: 'IMPOSSIBLE'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1220kb

input:

c
x

output:

21

result:

ok single line: '21'

Test #3:

score: 10
Accepted
time: 0ms
memory: 1220kb

input:

8
3

output:

5

result:

ok single line: '5'

Test #4:

score: 10
Accepted
time: 0ms
memory: 1228kb

input:

097
097

output:

0

result:

ok single line: '0'

Test #5:

score: 10
Accepted
time: 0ms
memory: 1224kb

input:

135409
357621

output:

2

result:

ok single line: '2'

Test #6:

score: 10
Accepted
time: 0ms
memory: 1264kb

input:

ulhpnmrkblwafxapsldccdplmqukqlxwixjtleoirjyyivdguyiffnvunoxconwjvovmqluhyypgfkmdvgpzjuepkwjdoniezcli...

output:

21

result:

ok single line: '21'

Test #7:

score: 10
Accepted
time: 0ms
memory: 1264kb

input:

ijvxljtolmgjndlwoyjjttakhzvzmihjdhkyfnafwrpeuiuiurusvsnugviqzouvuxalhxmxhclxdzrxylbzsmdruqpnvagkninp...

output:

13

result:

ok single line: '13'

Test #8:

score: 10
Accepted
time: 1ms
memory: 1268kb

input:

lb3zc66k080upg8dfv18jctk0sejke93251mw9f3642u1x7889s5y38wdv39391v3gptt6656248xw576z2w27gh9t3wh5j634lg...

output:

22

result:

ok single line: '22'

Test #9:

score: 10
Accepted
time: 0ms
memory: 1264kb

input:

h18855603165ay78uft01r1i89sx9o1z6d1h0nd2l8f28xe05571r64vjeofr32453571pa1z9x47dpg5k3uw2027lx4270g4xyh...

output:

98

result:

ok single line: '98'

Test #10:

score: 10
Accepted
time: 0ms
memory: 1268kb

input:

2c3hoz6dbcggcjjf665nqfcy3w2yoej1lyr1j523230e2q228b6vn96gsuq1sustb1269uiyrk6y3gi883f789rro7nomg9776w1...

output:

129

result:

ok single line: '129'

Extra Test:

score: 0
Extra Test Passed