zoukankan      html  css  js  c++  java
  • hdu-6170(模拟)

    Two strings

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 1964    Accepted Submission(s): 753

    Problem Description
    Giving two strings and you should judge if they are matched.
    The first string contains lowercase letters and uppercase letters.
    The second string contains lowercase letters, uppercase letters, and special symbols: “.” and “*”.
    . can match any letter, and * means the front character can appear any times. For example, “a.b” can match “acb” or “abb”, “a*” can match “a”, “aa” and even empty string. ( “*” will not appear in the front of the string, and there will not be two consecutive “*”.
     
    Input
    The first line contains an integer T implying the number of test cases. (T≤15)
    For each test case, there are two lines implying the two strings (The length of the two strings is less than 2500).
     
    Output
    For each test case, print “yes” if the two strings are matched, otherwise print “no”.
     
    Sample Input
    3
    aa
    a* abb
    a.* abb
    aab
     
    Sample Output
    yes
    yes
    no
     
      题意:给2个字符串问这2个字符串是否匹配,第二个字符串有2个特殊字符“."和“*”,“."可以代表任何字符,“*”可以代表前一个字符可以出现的次数和位置不限,“*”不会出现在第一个,不会出现连续两个“*”。
      按题意模拟即可。
      
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<set>
    #include<map>
    #include<queue>
    #include<vector>
    #define ll long long int
    #define INF 0x7fffffff
    #define MAX 200005
    #define me(a,b) memset(a,b,sizeof(a))
    using namespace std;
    int main()
    {
        int t;
        set<char> sa,sb;
        char a[2505],b[2505];
        bool fa[2505];
        while(cin>>t)
        while(t--){
            cin>>a>>b;
            me(fa,false);
            sa.clear();
            sb.clear();
            int la=strlen(a),lb=strlen(b);
            int i=0,j=0,k=0;
            for(i=0;i<lb,j<la;i++){
                if(b[i]=='.'){
                    if(b[i+1]=='*')
                        k++;
                    else{
                        fa[j]=true;
                        j++;
                    }
                }
                else if(b[i]=='*')
                    continue;
                else{
                    if(b[i+1]=='*')
                        sb.insert(b[i]);
                    else{
                        while(b[i]!=a[j]&&j<la){
                            j++;
                        }
                        if(b[i]==a[j])
                            fa[j]=true;
                        j++;
                    }
                }
            }
            bool flag=true;
            for(;i<lb;i+=2){
                if(b[i+1]!='*'){
                    flag=false;
                    break;
                }
                else{
                    if(b[i]=='.')
                        k++;
                    else
                        sb.insert(b[i]);
                }
            }
            if(!flag){
                cout<<"no"<<endl;
                continue;
            }
            for(i=0;i<la;i++){
                if(fa[i]==false){
                    if(sb.find(a[i])==sb.end()){
                        if(k==0){
                            flag=false;
                            break;
                        }
                        else{
                            k--;
                            sb.insert(a[i]);
                        }
                    }
                }
            }
            if(!flag)
                cout<<"no"<<endl;
            else
                cout<<"yes"<<endl;
        }
    }
  • 相关阅读:
    java 大数据处理类 BigDecimal 解析
    关于纠正 C/C++ 之前在函输内改变 变量的一个错误想法。
    C++ 制作 json 数据 并 传送给服务端(Server) 的 php
    介绍一个很爽的 php 字符串特定检索函数---strpos()
    如何 判断 设备 是否 连接 上 了 wifi
    android 通过访问 php 接受 or 传送数据
    正则匹配抓取input 隐藏输入项和 <td>标签内的内容
    手把手教你Chrome扩展开发:本地存储篇
    HTML5之本地存储localstorage
    初尝CDN:什么是分布式服务节点?
  • 原文地址:https://www.cnblogs.com/DarkFireMater/p/7989790.html
Copyright © 2011-2022 走看看