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

逐个去匹配即可

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

 

UVa 10340 All in All_#endifUVa 10340 All in All_字符串_02
 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 }
代码君