-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrypt Kicker II.cpp
75 lines (73 loc) · 1.34 KB
/
Crypt Kicker II.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<set>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
bool isMatch(string &d, string &s, unordered_map<char, char> &dict) {
dict[' '] = ' ';
if (d.size() != s.size()) return false;
unordered_set<char> used;
used.insert(' ');
for (int i = 0; i < d.size(); i++) {
if (!dict.count(d[i])) {
if (used.count(s[i])) {
return false;
}
else {
dict[d[i]] = s[i];
}
}
else {
if (s[i] != dict[d[i]]) {
return false;
}
}
}
return true;
}
int main() {
//freopen("d:\\in.txt", "r", stdin);
//freopen("d:\\out.txt", "w", stdout);
string s = "the quick brown fox jumps over the lazy dog";
int t;
cin >> t;
getchar();
getchar();
while (t--) {
vector<string> crypt;
string oneline;
while (getline(cin, oneline) && oneline!="") {
crypt.push_back(oneline);
}
unordered_map<char, char> dict;
dict.clear();
for (auto &val : crypt) {
if (isMatch(val, s,dict)) {
break;
}
else {
dict.clear();
}
}
if (dict.empty()) {
cout << "No solution." << endl;
}
else {
//decrypt
for (auto &val : crypt) {
for (auto &c : val) {
putchar(dict[c]);
}
if(t) putchar('\n');
}
}
if(t) cout << endl;
}
return 0;
}