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

UVa 10340 All in All

时间:2014-08-26 09:38:25      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   for   ar   art   

验证第二个字符串删去若干个字符后能否得到第一个字符串

逐个去匹配即可

只不过思维还不够严密,WA了几次开始

 

bubuko.com,布布扣
 1 //#define LOCAL
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 
 6 const int maxn = 100000 + 10;
 7 char s1[maxn], s2[maxn];
 8 
 9 int main(void)
10 {
11     #ifdef LOCAL
12         freopen("10340in.txt", "r", stdin);
13     #endif
14 
15     while(scanf("%s %s", s1, s2) == 2)
16     {
17         int len1 = strlen(s1);
18         int len2 = strlen(s2);
19         int i, p = 0;
20         bool flag;
21         for(i = 0; i < len1; ++i)
22         {
23             flag = false;
24             if(len1 - i > len2 - p)
25                 break;
26             while(s1[i] != s2[p] && p < len2) ++p;
27             if(s1[i] == s2[p])
28             {    
29                 flag = true;
30                 ++p;
31             }
32         }
33         if(flag && i == len1)    printf("Yes\n");
34         else    printf("No\n");
35     }
36     return 0;
37 }
代码君

 

UVa 10340 All in All

标签:style   blog   http   color   os   io   for   ar   art   

原文地址:http://www.cnblogs.com/AOQNRMGYXLMV/p/3936411.html

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