-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpasswordsOJ.cpp
71 lines (65 loc) · 1.44 KB
/
passwordsOJ.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
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
void solve(vector<string> & dictionary, string nowRule, int nowPos, string ans)
{
int Dsize = dictionary.size();
int Rsize = nowRule.size();
if (nowPos == Rsize)
{
cout << ans << '\n';
}
else if (nowRule[nowPos] == '0')
{
for (int i = 0; i <= 9; ++i)
{
char temp = i + '0';
solve(dictionary, nowRule, nowPos + 1, ans + temp);
}
}
else
{
for (int i = 0; i <= Dsize - 1; ++i)
{
solve(dictionary, nowRule, nowPos + 1, ans + dictionary[i]);
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
while (true)
{
int Dsize = 0;
cin >> Dsize;
if (Dsize == 0)
{
break;
}
cout << "--\n";
vector<string> dictionary(Dsize);
for (int i = 0; i <= Dsize - 1; ++i)
{
cin >> dictionary[i];
}
int Rtotal;
cin >> Rtotal;
for (int i = 1; i <= Rtotal; ++i)
{
string nowRule;
cin >> nowRule;
solve(dictionary, nowRule, 0, "");
}
}
cout.flush();
return 0;
}