首页 > 其他 > 详细

习题3-10 All in All UVA - 10340

时间:2018-09-16 13:28:16      阅读:156      评论:0      收藏:0      [点我收藏+]

水题,记两个位置,依次遍历,从头找到尾就行了,对每个用例,复杂度o(min(s.size(),t.size())).

#include <bits/stdc++.h>
using namespace std;
string s,t;
int main()  {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (cin>>s>>t)   {
        int spos=0,tpos=0;
        while (spos!=(int)s.size()&&tpos<(int)t.size())  {
            if (s[spos]==t[tpos])
                spos++,tpos++;
            else    tpos++;
        }
        if (spos==(int)s.size()) cout<<"Yes"<<endl;
        else    cout<<"No"<<endl;
    }
    return 0;
}

习题3-10 All in All UVA - 10340

原文:https://www.cnblogs.com/yichuan-sun/p/9655265.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!