UVA - 10340 - All in All

题目:https://cn.vjudge.net/problem/UVA-10340

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char s[1000005],t[1000005];
int main()
{
    int k,n;
    while(scanf("%s%s",s,t)!=EOF)
    {
        n=k=0;
        for(int j=0;s[j]!='\0';j++)
        {
            for(int i=k;t[i]!='\0';i++)
            {
                if(s[j]==t[i])
                {
//                    cout<<j<<" "<<i<<endl;
//                    cout<<s[j]<<" "<<t[i]<<endl;
                    n++;
                    k=i+1;
                    break;
                }
            }
        }
        if(n==strlen(s))
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}
AC Code

思路:

        两个字符串要顺序查找,找到对应的一个字符后,两者只能继续往后找,注意循环的位置

posted @ 2018-07-14 09:45  子诚-  阅读(132)  评论(0编辑  收藏  举报