UVa 10340 - All in All 水题 难度: 0

本文介绍了一个简单的算法,用于判断一个字符串是否为另一个字符串的子序列。通过遍历两个字符串并进行字符匹配,如果所有字符都能按顺序匹配,则第一个字符串是第二个字符串的子序列。文章附带了C++实现代码。

题目

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1281


题意

问字符串a能否是字符串b的子序列

 

思路

明显,计数对的上就行

 

感想

因为忘了break错了一次 

 

代码

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<int, int> MyPair;

int main() {
#ifdef LOCAL_DEBUG
    freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
    //freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
    int T;
    string a, b;
    for (int ti = 1;cin>>a>>b; ti++) {
        int sza = 0, szb = 0;
        for (sza = 0, szb = 0; sza < a.size() && szb < b.size(); sza++, szb++) {
            while (szb < b.size() && a[sza] != b[szb]) { szb++; }
            if (szb >= b.size())break;
        }
        if (sza == a.size())puts("Yes");
        else puts("No");
    }

    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/xuesu/p/10463059.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值