• NOIP模拟----string


    题目

                                字符串string.cpp 
    

    【描述】
    给定两个字符串s,t,其中s 只包含小写字母以及*,t 只包含小写字母。
    你可以进行任意多次操作,每次选择s 中的一个*,将它修改为任意多个(可以是0 个)它
    的前一个字符。问是否能将s 修改为t。
    有多组数据。
    【输入】
    第一行一个整数T 表示数据组数。
    每组数据两行,第一行一个字符串s,第二行一个字符串t。
    【输出】
    每组数据输出一行,如果能将s修改为t,输出Yes,否则输出No。
    【输入样例】
    2
    a*
    aaaa
    a*
    ab
    【输出样例】
    Yes
    No
    【子任务】
    对于20%的数据,|s|,|t|<=7。
    对于60%的数据,|s|,|t|<=300。
    对于100%的数据,T<=100,|s|,|t|<=30000。

    很简单的一道模拟题,只不过要考虑的情况很多,也不好调,多对着大数据对拍几次,把所有的情况都考虑到就好了;

    #include<bits/stdc++.h>
    using namespace std;
    int T,lena,lenb;
    char s[30005],t[30005];
    bool ans=true;
    inline void then(int &a,int &b){
        int f=a-1,k=b,c=0;
        while((s[a]=='*'||s[a]==s[f])) 
        {
            if(s[a]=='*') c++;
            a++;
        }
        while(s[a]==s[f]) a++;
        while(s[f]==t[b]) b++;
        if((b-k)<(a-f-1-c))  ans=false;
    }
    int main(){
        scanf("%d",&T);
        while(T--)
        {
            cin>>s+1;
            cin>>t+1;
            lena=1,lenb=1;
            while((s[lena]<='z'&&s[lena]>='a')||(s[lena]=='*')) lena++;
            lena--;
            while(t[lenb]<='z'&&t[lenb]>='a') lenb++;
            lenb--;
            int x=1,y=1,num=0;
            for(int i=1;i<=lena;i++){
                if(s[i]=='*') num++;
            }
            if(lena>lenb+num)
            {
                cout<<"No"<<endl;
                continue;
            }
            ans=true;
            while(x<=lena&&y<=lenb&&ans)
            {
                if(s[x]!='*')
                {
                    if(s[x]==t[y])
                    {
                        x++,y++;
                    }
                    else
                    {
                        ans=false;
                        break;
                    }
                }
                else 
                {
                    then(x,y);
                }
            }
            while(x<=lena&&s[x]=='*') x++;
            if(x<=lena||y<=lenb)
            ans=false;
            if(ans) cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
    }
  • 相关阅读:
    动态与静态Include
    java回收算法
    reflection是如何工作的。
    hashcode和equals的约定关系如下
    Java调试器
    混合赋值运算符的使用
    Spring
    Math.?
    oracle--触发器(转)
    oracle --游标详解(转)
  • 原文地址:https://www.cnblogs.com/forever-/p/9736086.html
Copyright © 2020-2023  润新知