码迷,mamicode.com
首页 > 其他好文 > 详细

poj 1936 All in All

时间:2014-10-09 14:16:23      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   strong   sp   

题目链接: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\n");
        else 
            printf("No\n");
    }

    return 0;
}

 

poj 1936 All in All

标签:style   blog   http   color   io   os   ar   strong   sp   

原文地址:http://www.cnblogs.com/tallisHe/p/4012384.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!