All in All

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

题目大意:判断从字符串s2中能否找到子串s1。字符串长度为10W。

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output

Yes
No
Yes
No

分析:这明明是模拟题,有人竟然把它归为动态规划,是要用LCS做吗

代码如下:

 1 # include<stdio.h>
 2 # include<string.h>
 3 # define MAX 100005
 4 char s1[MAX],s2[MAX];
 5 int main(){
 6     while(scanf("%s%s",s1,s2)!=EOF){
 7         int len1 = strlen(s1);
 8         int len2 = strlen(s2);
 9         int i=0;
10         int j=0;
11         while(1){
12             if(i==len1){
13                 printf("Yes\n");
14                 break;
15             }
16             else if(j==len2){
17                 printf("No\n");
18                 break;
19             }
20             if(s1[i]==s2[j])
21                 i++,j++;
22             else
23                 j++;
24         }
25     }
26     return 0;
27 }

 

 

相关文章:

  • 2022-12-23
  • 2021-12-13
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
猜你喜欢
  • 2021-07-28
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-02
  • 2021-10-17
  • 2021-12-03
相关资源
相似解决方案