-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword.cpp
98 lines (90 loc) · 2.34 KB
/
password.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("password.in");
ofstream fout("password.out");
int main()
{
int total;
fin >> total;
for (int i = 1; i <= total; ++i)
{
int k;
fin >> k;
vector<vector<char>> list0(6,vector<char>(5));
for (int y = 0; y <= 5; ++y)
{
for (int x = 0; x <= 4; ++x)
{
fin >> list0[y][x];
}
}
vector<vector<char>> list1(6,vector<char>(5));
for (int y = 0; y <= 5; ++y)
{
for (int x = 0; x <= 4; ++x)
{
fin >> list1[y][x];
}
}
vector<set<char>> repeats(5);
for (int x = 0; x <= 4; ++x)
{
vector<bool> dp(26,false);
for (int y = 0; y <= 5; ++y)
{
dp[list0[y][x] - 'A'] = true;
}
for (int y = 0; y <= 5; ++y)
{
if (dp[list1[y][x] - 'A'] == true)
{
repeats[x].insert(list1[y][x]);
}
}
}
vector<int> nums;
nums.push_back(1);
for (int x = 4; x >= 0; --x)
{
nums.push_back(nums.back() * repeats[x].size());
}
if (nums.back() * repeats[0].size() < k)
{
fout << "NO\n";
}
else
{
int left = k - 1;
for (int i = 4; i >= 0; --i)
{
if (repeats[4 - i].size() == 1)
{
fout << *(repeats[4 - i].begin());
left %= nums[i];
continue;
}
else if (left / nums[i] >= repeats[4 - i].size())
{
fout << "NO";
break;
}
auto it = repeats[4 - i].begin();
advance(it, left / nums[i]);
char nowChar = *it;
fout << nowChar;
left %= nums[i];
}
fout << '\n';
}
}
return 0;
}