Codeforces 1023 A.Single Wildcard Pattern Matching-匹配字符 (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)

 

Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

 

 

A. Single Wildcard Pattern Matching

 

题意就是匹配字符的题目,打比赛的时候没有看到只有一个" * ",然后就写挫了,被hack了,被hack的点就是判一下只有一个" * "。

 

代码:

 1 //A
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<bitset>
 7 #include<cassert>
 8 #include<cctype>
 9 #include<cmath>
10 #include<cstdlib>
11 #include<ctime>
12 #include<deque>
13 #include<iomanip>
14 #include<list>
15 #include<map>
16 #include<queue>
17 #include<set>
18 #include<stack>
19 #include<vector>
20 using namespace std;
21 typedef long long ll;
22 
23 const double PI=acos(-1.0);
24 const double eps=1e-6;
25 const ll mod=1e9+7;
26 const int inf=0x3f3f3f3f;
27 const int maxn=2*1e5+10;
28 const int maxm=100+10;
29 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
30 
31 char s[maxn],t[maxn];
32 
33 int main()
34 {
35     int n,m;
36     scanf("%d%d",&n,&m);
37     scanf("%s%s",s,t);
38     int pos=-1;
39     for(int i=0;i<n;i++){
40         if(s[i]=='*'){
41             pos=i;
42             break;
43         }
44     }
45     if(pos==-1){
46         if(n!=m)
47             cout<<"NO"<<endl;
48         else{
49             for(int i=0;i<n;i++){
50                 if(s[i]!=t[i]){
51                     cout<<"NO"<<endl;
52                     return 0;
53                 }
54             }
55             cout<<"YES"<<endl;
56         }
57     }
58     else{
59         if(m<n-1){
60             cout<<"NO"<<endl;
61             return 0;
62         }
63         for(int i=0;i<pos;i++){
64             if(s[i]!=t[i]){
65                 cout<<"NO"<<endl;
66                 return 0;
67             }
68         }
69         for(int i=n-1,j=m-1;i>pos;i--,j--){
70             if(s[i]!=t[j]){
71                 cout<<"NO"<<endl;
72                 return 0;
73             }
74         }
75         cout<<"YES"<<endl;
76     }
77 }

 

 

 

 

posted @ 2018-08-19 17:32  ZERO-  阅读(232)  评论(0编辑  收藏  举报