-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path0071.cpp
44 lines (40 loc) · 854 Bytes
/
0071.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
43
44
// 0071.字符串通配符
// keywords: 递归
#include <iostream>
using namespace std;
bool match(string a, string b)
{
// 可以做一下剪枝
for(int i = 0, j = 0; i < a.size(); i++, j++)
{
if (a[i] == '*') {
bool f = false;
string s = a.substr(i+1);
for (int k = j; k < b.size(); k++)
{
f = f || match(s, b.substr(k));
}
return f;
}
else if (a[i] == '?') {
continue;
}else if (a[i] != b[j]) {
return false;
}
}
return true;
}
int main()
{
string a, b;
while(getline(cin, a))
{
getline(cin, b);
if (match(a, b)) {
cout << "true" << endl;
}else {
cout << "false" << endl;
}
}
return 0;
}