在一行上输入两个字符串s和英文字符串t,要求在s中查找t。其中,字符串s,t均不包含空格,且长度均小于80。
输入格式:
首先输入一个正整数T,表示测试数据的组数,然后是T组测试数据。每组测试输入2个长度不超过80的字符串s和t(s和t都不包含空格)。
输出格式:
对于每组测试数据,若在s中找到t,则输出Found!
,否则输出not Found!
。
输入样例:
2
dictionary lion
factory act
输出样例:
not Found!
Found!
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
#include <stdio.h>
#include <string.h>
int main() {
char str1[81];
char str2[81];
int t;
scanf("%d ", &t);
for (int i = 0; i < t; i++) {
scanf("%s %s", str1, str2);
//求字符串长度
int sum1 = strlen(str1);
int sum2 = strlen(str2);
int count = 0;
//进入循环匹配
for (int j = 0; j < sum1; j++) {
if (str1[j] == str2[count]) {//如果匹配count++,
count++;
} else {//如果不匹配count归零
count = 0;
}if (count == sum2){//如果连续连续匹配次数满足字符串str2c长度退出循环
break;
}
}
if(count == sum2)
printf("Found!\n");
else
printf("not Found!\n");
}
return 0;
}