-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path628.cpp
42 lines (37 loc) · 957 Bytes
/
628.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
/*
brute force > iterative
difficulty: easy
date: 14/Apr/2020
by: @brpapa
*/
#include <bits/stdc++.h>
using namespace std;
// retorna o d-ésimo dígito de num, sendo o 0-ésimo dígito aquele mais à direta
int dig(int num, int d) {
while (d--) num /= 10;
return num % 10;
}
int main() {
int N;
while (cin >> N) {
vector<string> words(N);
for (string &word : words) cin >> word;
cout << "--" << endl;
int M; cin >> M;
while (M--) {
string rule; cin >> rule;
int count0 = 0; for (char c : rule) if (c == '0') count0++;
for (string word : words) {
for (int num = 0; num < pow(10, count0); num++) {
int d = count0-1;
for (char c : rule) {
if (c == '0') cout << dig(num, d--);
else cout << word;
}
cout << endl;
}
}
}
}
return 0;
}