POJ 1936 All in All

版权声明:听说这里让写版权声明~~~ https://blog.csdn.net/m0_37691414/article/details/82115049

题意:给出两个字符串s和t,判断s是不是t的子串(不用连续)

解析:只需要判断是否匹配不用开数组,所以直接暴力解决.

#include<iostream>  
#include<string>  
using namespace std;  
int main()  
{  
    char s[100005],t[100005];  
    int i,j,len1,len2;  
    while(scanf("%s %s",s,t)!=EOF)  
    {   
        len1=strlen(s);  
        len2=strlen(t);  
        i=0;  
        j=0;  
        while(i<len1 && j<len2)  
        {  
            if(s[i]==t[j])  
            {  
                i++;  
                j++;   
            }  
            else  
            {  
                j++;  
            }  
        }  
        if(i==len1)  
            cout<<"Yes"<<endl;  
        else  
            cout<<"No"<<endl;  

    }  
    return 0;  
} 

猜你喜欢

转载自blog.csdn.net/m0_37691414/article/details/82115049
ALL