习题3-10 All in All UVA - 10340

水题,记两个位置,依次遍历,从头找到尾就行了,对每个用例,复杂度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;
}

猜你喜欢

转载自www.cnblogs.com/yichuan-sun/p/9655265.html
ALL