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;
        }
    }
  • 相关阅读:
    spark读取文件时对字符编码的支持
    SparkSQL 数据分页及Top N
    linux下添加hadoop用户
    Window 10 WSL 下hadoop 伪分布式安装
    Window 10下spark shell使用sparksql 时的 “entry in command string: null ls -F C: mphive”问题解决
    spark数据怎样输出到Sql Server
    spark standalone集群模式下一个启动问题的解决
    Ubuntu 上redis 5.0的安装
    apache ambari 部署分布式系统
    Ubuntu18.04 下 Spark 2.4.3 standalone模式集群部署
  • 原文地址:https://www.cnblogs.com/DarkFireMater/p/7989790.html
Copyright © 2011-2022 走看看