-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path201803-3.cpp
More file actions
89 lines (76 loc) · 2.13 KB
/
201803-3.cpp
File metadata and controls
89 lines (76 loc) · 2.13 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
87
88
89
/* CCF201803-3 URL映射 */
#include<bits/stdc++.h>
using namespace std;
const int N = 100;
string p[N], r[N], s;
bool match(string& s, string& t, bool flag)
{
int lent = t.size();
int lens = s.size();
int ps = 0, pt = 0;
while(ps < lens && pt < lent) {
if(t[pt] == s[ps]) {
ps++, pt++;
} else {
// 匹配<xxx>
if(t[pt++] != '<')
return false;
if(flag)
cout << ' ';
if(t[pt] == 'i') {
// 匹配<int>
bool ok = false;
while(s[ps] && isdigit(s[ps])) {
if(s[ps] != '0')//去掉前导零
ok = true;
if(flag && ok)
cout << s[ps];
ps++;
}
if(!ok)
return false;
pt += 4;
} else if(t[pt] == 's') {
// 匹配<str>
bool ok = false;
while(s[ps] && s[ps] != '/') {
ok = true;
if(flag)
cout << s[ps];
ps++;
}
if(!ok)
return false;
pt += 4;
} else if(t[pt] == 'p') {//如果合法的话,<path>一定已经是最后一个了
// 匹配<path>
if(flag)
while(s[ps])
cout << s[ps++];
return true;
}
}
}
return pt == lent && ps == lens;
}
int main()
{
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++)
cin >> p[i] >> r[i];
for(int i = 0; i < m; i++) {
cin >> s;
bool flag = true;
for(int j = 0; flag && j < n; j++)
if(match(s, p[j], false)) {//用了两次match,true的时候会输出
flag = false;
cout << r[j];
match(s, p[j], true);
}
if(flag)
cout << "404";
cout << endl;
}
return 0;
}