-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva-628.cpp
More file actions
63 lines (57 loc) · 1.22 KB
/
uva-628.cpp
File metadata and controls
63 lines (57 loc) · 1.22 KB
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
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;
string ptrn;
int idx;
vector<int>numbers;
vector<string>words;
void print(){
int j = 0;
for (int i = 0;i<ptrn.size();i++){
if (ptrn[i] == '#') cout<<words[idx];
else cout<<numbers[j++];
}
cout<<'\n';
}
void solve(int depth,int limit){
if (depth >= limit) {
print();
return;
}
for (int i = 0;i<=9;i++){
numbers.push_back(i);
solve(depth+1,limit);
numbers.pop_back();
}
}
int zeroCount(){
int cnt = 0;
for (int i = 0;i<ptrn.size();i++)
if (ptrn[i] == '0') cnt++;
return cnt;
}
int main(){
ios_base::sync_with_stdio(0);
int n,m; string word, pattern;
while (cin >> n){
for (int i = 0;i < n;i++) {
cin >> word;
words.push_back(word);
}
cin >> m;
for (int i = 0;i< m; i++) {
int cnt = 0;
cin >> pattern;
cout<<"--"<<'\n';
ptrn = pattern;
for (int i = 0; i < n; i++){
idx = i;
solve(0,zeroCount());
}
}
words.clear();
numbers.clear();
}
}