Description
给出两个字符串S和T,请判断T是否为S的子串。本题请用"简单匹配法"来做。 使用strstr函数,判cheat
Input
第一行是一个整数N,说明有多少个测试用例。
接下来是N个测试用例,每个测试用例占2行:第一行是字符串S,第二行是字符串T,字符串中不含空格。 1 ≤ strlen(S) , strlen( T ) ≤ 10000
Output
对每个测试用例,输出一行结果:是否子串,是则输出"yes" ,否则输出 "no"
Sample Input
2
aabcdd
abc
aaaaaaaaaaaaa
aaaaaab
Sample Output
yes
no
#include<stdio.h>
#include<string.h>
int main(void){
int t, j, id, g, d;
char s[10005], c[10005], cha;
scanf("%d", &t);
cha=getchar();
for(g=1; g<=t; g++){
gets(s); gets(c);
for(j=0,id=0,d=0; j<strlen(s); j++){
if(s[j]!=c[id]) id=0;
if(s[j]==c[id]) id++;
if(id==strlen(c)) { d++; break; }
}
if(d!=0) printf("yes\n");
else printf("no\n");
}
return 0;
}