题目描述
给定两个字符串string1和string2,判断string2是否为string1的子串。
输入
输入包含多组数据,每组测试数据包含两行,第一行代表string1,第二行代表string2,string1和string2中保证不出现空格。
输出
对于每组输入数据,若string2是string1的子串,则输出"YES",否则输出"NO"。
示例输入
abc
a
123456
45
abc
ddd
示例输出
YES
YES
NO
1 #include<stdio.h>
2 #include<
string.h>
3 int main()
4 {
5 char s1[
65535],s2[
65535];
6 int i,j,start;
7 while(~scanf(
"%s %s",s1,s2))
8 {
9 start =
0;
10 i =
start;
11 j =
0;
12 while(i < strlen(s1) && j <
strlen(s2))
13 {
14 if(s1[i] ==
s2[j])
15 {
16 i++
;
17 j++
;
18 }
19 else
20 {
21 start++
;
22 i =
start;
23 j =
0;
24 }
25 }
26 if(j ==
strlen(s2))
27 {
28 printf(
"YES\n");
29 }
30 else printf(
"NO\n");
31 }
32 return 0;
33 }
View Code
转载于:https://www.cnblogs.com/LK1994/p/3157357.html