UVa 10340 All in All

  一道简单的比较查找题,刚开始数组开得不够大,RE。

  代码如下:

View Code
 1 #include <cstdio>
 2 #include <cstring>
 3 using namespace std;
 4 
 5 const int maxn = 1000000;
 6 char s[maxn], t[maxn];
 7 int main()
 8 {
 9 #ifdef LOCAL
10     freopen("in", "r", stdin);
11 #endif
12     int slen, tlen;
13     while(scanf("%s%s", s, t) != EOF)
14     {
15         slen = strlen(s);
16         tlen = strlen(t);
17         int p = 0;
18         for(int i = 0; i < tlen; i++)
19         {
20             if(t[i] == s[p])   p++;
21             if(p >= slen) break;
22         }
23         if(p >= slen)   printf("Yes\n");
24         else printf("No\n");
25     }
26     return 0;
27 }

   判断s是否是t的一个子序列。

原文地址:https://www.cnblogs.com/xiaobaibuhei/p/3022498.html