poj 1936 All in All(水题)

题目链接:http://poj.org/problem?id=1936

思路分析:字符串子序列查找问题,设置两个指针,一个指向子序列,另一个指向待查找的序列,查找个字符串一次即可判断。算法时间复杂度O(N)。

代码如下: 

#include <cstdio>
#include <cstring>
using namespace std;

#define MAX_LEN 100000 + 1

char s[MAX_LEN], t[MAX_LEN];

bool to_find(const char *s1, const char *s2) 
{
    while (*s1 && *s2)
     {
        if (*s1 == *s2)
            ++ s1;

        ++ s2;
    }

    if (*s1)
        return false;
    else
        return true;
}

int main()
{
    while (scanf("%s %s", s, t) != EOF) 
    {
        if (to_find(s, t)) 
            printf("Yes
");
        else 
            printf("No
");
    }

    return 0;
}
原文地址:https://www.cnblogs.com/tallisHe/p/4012384.html