UVA 10340 子序列

    水题一道,不涉及什么算法,注意s串和t串的输入顺序就好,搞清楚是在t串中去找s串,而不是在s串中去找t串,所以接下来的工作,就是用一个for循环来依次做最为朴素的匹配就好,如果ans==s串的长度,那么就说明匹配了.注意细节,稳稳出题。


# include<cstdio>
# include<iostream>
# include<cstring>

using namespace std;

# define MAX 100000

char s[MAX+10];
char t[MAX+10];

int main(void)
{
    while ( scanf("%s%s",s,t)!=EOF )
    {
        //scanf("%s",t);
        int n1 = strlen(s);
        int n2 = strlen(t);
        int ans = 0;
        for ( int i = 0, j = 0;i < n1&&j < n2; )
        {
            if ( s[i] == t[j] )
                {
                    i++;
                    j++;
                }
                else
                    j++;

                ans = i;
        }
        if ( ans == n1 )
            cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值