-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva628.cpp
48 lines (41 loc) · 944 Bytes
/
uva628.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
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<string> words;
void print_ans(string templa, int curidx, string ans) {
int len = templa.length();
if(curidx == len) cout << ans << endl;
if(templa[curidx] == '#') {
for(int i = 0; i < words.size(); ++i) {
string temp = ans;
temp += words[i];
print_ans(templa, curidx + 1, temp);
}
}else if(templa[curidx] == '0') {
for(int i = 0; i < 10; ++i) {
string temp = ans;
temp += (char)(i + '0');
print_ans(templa, curidx + 1, temp);
}
}
}
int main() {
int nwords, ntemplate;
string in;
while(cin >> nwords) {
words.clear();
cout << "--" << endl;
for(int i = 0; i < nwords; ++i) {
cin >> in;
words.push_back(in);
}
cin >> ntemplate;
for(int i = 0; i < ntemplate; ++i) {
cin >> in;
print_ans(in, 0, "");
}
}
return 0;
}