zoukankan      html  css  js  c++  java
  • codeforces-1023 A Single Wildcard Pattern Matching

     1 #include <iostream>
     2 #include <unordered_map>
     3 #include <algorithm>
     4 #include <vector>
     5 #include <queue>
     6 
     7 using namespace std;
     8 
     9 int main()
    10 {
    11     int n,m;
    12     while(cin >> n >> m)
    13     {
    14         string s,t;
    15         cin >> s >> t;
    16         if(m+1<n)
    17         {
    18             cout << "NO" << endl;
    19             continue;
    20         }
    21         int s_index = 0;
    22         int t_index = 0;
    23         int flag = 0;
    24         for(int i = 0; i < n; i ++)
    25         {
    26             if(s[i]=='*')
    27                 break;
    28             else if(i==n-1 && m!=n)
    29             {
    30                 cout << "NO" << endl;
    31                 flag = 1;
    32                 break;
    33             }
    34         }
    35         if(flag!=1)
    36         {
    37             while(t_index<m)
    38             {
    39                 if(s[s_index]=='*')
    40                 {
    41                     flag = 2;
    42                     break;
    43                 }
    44                 else
    45                 {
    46                     if(s[s_index]!=t[t_index])
    47                     {
    48                         cout << "NO" << endl;
    49                         flag = 1;
    50                         break;
    51                     }
    52                     s_index ++;
    53                     t_index ++;
    54                 }
    55             }
    56         }
    57         if(flag==2)
    58         {
    59             s_index = n-1;
    60             t_index = m-1;
    61             while(s[s_index]!='*')
    62             {
    63                 if(s[s_index]!=t[t_index])
    64                 {
    65                     cout << "NO" << endl;
    66                     flag = 1;
    67                     break;
    68                 }
    69                 s_index --;
    70                 t_index --;
    71             }
    72             if(flag==2)
    73                 flag = 0;
    74         }
    75         if(flag==0)
    76             cout << "YES" << endl;
    77     }
    78     return 0;
    79 }
  • 相关阅读:
    注册表修改 Devenv 默认启动 Visual Studio 版本
    python——高级特性(2)
    python——高级特性
    Hibernate—部分
    Filter—过滤器和拦截器的区别
    POST—常见的4种提交方式
    POST—GET—两种提交方式的区别
    JSON—fastJSON
    协程小示例
    协程基础
  • 原文地址:https://www.cnblogs.com/Asurudo/p/9496135.html
Copyright © 2011-2022 走看看