不难 听了出题人讲思路马上就会 但我就是要搞题解 纪念我的赛场自闭四小时
最坑的是25对推第26对 双向映射一一对应 直接数组存 感觉也许是输在英语不好?
Description Little Sub builds a naive Enigma machine of his own. It can only be used to encrypt/decrypt lower-case letters by giving each letter a unique corresponding lower-case letter. In order to ensure the accuracy, no contradiction or controversy is allowed in both the decryption and the encryption, which means all lower-case letters can only be decrypted/encrypted into a distinct lower-case letter. Now we give you a string and its encrypted version. Please calculate all existing corresponding relationship which can be observed or deducted through the given information. Input The first line contains a string S, indicating the original message. The second line contains a string T , indicating the encrypted version. The length of S and T will be the same and not exceed 1000000. Output we use a string like ’x->y’ to indicate that letter x will be encrypted to letter y. Please output all possible relationships in the given format in the alphabet order. However, if there exists any contradiction in the given information, please just output Impossible in one line. Author YE, Zicheng
放一下出题人,zjunb
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<queue>
using namespace std;
int a[27], b[27];
string s1, s2;
int main() {
while (cin >> s1 >> s2) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
int flag = 0;
for (int i = 0; i < s1.length(); i++) {
int t1, t2;
t1 = s1[i] - 'a' + 1;
t2 = s2[i] - 'a' + 1;
if (!a[t1]) a[t1] = t2;
else if (a[t1] != t2) {
cout << "Impossible" << endl;
flag = 1;
break;
}
if (!b[t2]) b[t2] = t1;
else if (b[t2] != t1) {
cout << "Impossible" << endl;
flag = 1;
break;
}
//复读,双向存
}
if (flag) continue;
//上面break的是for,还需要一个continue,晕了
int ai, bi = 0;
int cnt = 0;
for (int i = 1; i <= 26; i++) {
if (a[i] == 0) cnt++, ai = i;
if (cnt >= 2) continue;
}
if (cnt == 1)
for (int i = 1; i <= 26; i++)
if (b[i] == 0) bi = i;
if (bi) a[ai] = bi;//25推26
for (int i = 1; i <= 26; i++) {
if (a[i] ) {
char tmp1, tmp2;
tmp1 = i - 1 + 'a';
tmp2 = a[i] - 1 + 'a';
cout << tmp1 << "->" << tmp2 << endl;
}
}
}
return 0;
}
其他题莫得了 太菜了