forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA.cpp
More file actions
86 lines (80 loc) · 1.34 KB
/
Copy pathA.cpp
File metadata and controls
86 lines (80 loc) · 1.34 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
int L, D, N;
vector<char>::iterator vitr;
vector<vector<char> > mm;
string str;
int valid[20][30];
string ts[5005];
void run() {
mm.clear();
int idx = 0;
int cnt = 0;
while (true) {
vector<char> t;
if (str[idx] == '(') {
++idx;
while (str[idx] != ')') {
if (valid[cnt][str[idx] - 'a']) {
t.push_back(str[idx]);
}
++idx;
}
++cnt;
sort(t.begin(), t.end());
t.erase(unique(t.begin(), t.end()), t.end());
++idx;
} else {
if (valid[cnt][str[idx] - 'a']) {
t.push_back(str[idx]);
}
++cnt;
++idx;
}
mm.push_back(t);
if (idx == str.length()) break;
}
int res = 0;
REP(i,D) {
bool flag = true;
REP(j,L) {
bool found = false;
REP(k,mm[j].size()) {
if (mm[j][k] == ts[i][j]) {
found = true;
break;
}
}
if (!found) {
flag = false;
break;
}
}
if (flag) ++res;
}
cout << res << endl;
}
int main() {
cin >> L >> D >> N;
memset(valid, 0, sizeof(valid));
REP(i,D) {
cin >> str;
ts[i] = str;
REP(j,L) {
valid[j][str[j] - 'a'] = 1;
}
}
REP(i,N) {
cin >> str;
cout << "Case #" << i + 1 << ": ";
run();
}
return 0;
}