• 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;
        }
    }
  • 相关阅读:
    通过 AWS CLI 操作 AWS S3
    AWS S3文件存储服务器搭建(新)
    Vertx 接入MongoDB (九)
    Vertx 接入Redis (八)
    Vertx Mysql数据库优化 (七)
    Vertx 接入Mysql数据库 (六)
    Vertx 实现webapi实战项目(五)
    Vertx 实现webapi实战项目(四)
    Vertx 实现webapi实战项目(三)
    正则表达式:元字符(基本可用来匹配的字符)
  • 原文地址:https://www.cnblogs.com/DarkFireMater/p/7989790.html
Copyright © 2020-2023  润新知