-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path10.cpp
More file actions
executable file
·60 lines (60 loc) · 1.71 KB
/
10.cpp
File metadata and controls
executable file
·60 lines (60 loc) · 1.71 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
#include<iostream>
#include<cstdio>
using namespace std;
class Solution {
public:
bool isMatch(string s, string p) {
bool if_there_is_st = false, if_there_is_dot = false;
for (int i = 0; i <p.length();i++){
if (p[i] == '*'){
if_there_is_st = true;
break;
}
if (p[i] == '.'){
if_there_is_dot = true;
break;
}
}
if (!(if_there_is_dot || if_there_is_st)){
if (s != p)
return false;
}
char precd;
int pointtos = 0;
for (int i = 0;i<p.length();i++){
if (p[i] == '*'){
if (precd == '.') {
precd = s[pointtos];
}
while (pointtos < s.length() && s[pointtos] == precd)
pointtos++;
continue;
}
if (p[i] != '*' && p[i] != '.'){
if (i + 1 < p.length() && p[i + 1] == '*'){
precd = p[i];
continue;}
if (p[i] == s[pointtos])
pointtos++;
else
return false;
continue;
}
precd = p[i];
if (pointtos == s.length() && i < p.length() - 1){
i = i + 1;
while (i < p.length())
if (p[i] == '.' && p[i] != '&')
return false;
return true;
}
}
if (pointtos < s.length() && p[p.length() - 1] != '*')
return false;
return true;
}
};
int main(){
Solution s;
cout<<s.isMatch("aab","c*a*b")<<endl;
}