-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy path4.6.cpp
More file actions
60 lines (53 loc) · 1.28 KB
/
4.6.cpp
File metadata and controls
60 lines (53 loc) · 1.28 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
/*
* 题目名称:字符串匹配
* 题目来源:北京航天航空大学复试上机题
* 题目链接:http://dwz.win/GKJ
* 代码作者:杨泽邦(炉灰)
*/
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
const int MAXN = 1e3 + 10;
string texts[MAXN];
string pattern;
bool Equal(char x, char y) {
if(isalpha(x)&&isalpha(y)) {
return toupper(x) == toupper(y);
} else {
return x == y;
}
}
bool Match(string text, string pattern) {
for (int i = 0, j = 0; i < text.size() && j < pattern.size(); ++i, ++j) {
bool flag = false;
if (pattern[j] == '[') {
for (; pattern[j] != ']'; ++j) {
if (Equal(text[i], pattern[j])) {
flag = true;
}
}
} else if (Equal(text[i], pattern[j])) {
flag = true;
}
if (!flag) {
return false;
}
}
return true;
}
int main() {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; ++i) {
cin >> texts[i];
}
cin >> pattern;
for (int i = 0; i < n; ++i) {
if (Match(texts[i], pattern)) {
cout << i + 1 << " " << texts[i] << endl;
}
}
}
return 0;
}