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 52 53 54 55 56 57 58
| #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 () { 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; 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; 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; }
|