武汉科技大学ACM:1007: 文本编辑器

Problem Description

YB打算写一个功能强大的文本编辑器,并取一个炫酷拉风,高端优雅的名字,比如“YB牌文本编辑器”之类的。既然功能强大,那肯定得有个查找功能吧。但是他在完成这个功能的时候遇到一点小问题。现在来请求你的帮助。

给你一个文本串s和一个模式串t,你需要写一个程序来查找ts中出现了多少次。

Input

第一行是一个正整数T,表示总共有T组测试数据。

接下来有T组测试,每组测试数据包括两行。第一行是文本串s,长度不大于10000。第二行是模式串t,长度不大于10。都是只有小写字母组成的字符串。

Output

每组测试对应输出一个正整数答案,表示k在s中出现了多少次。

Sample Input

2
abababa
aba
abcabc
abc

Sample Output

3
2

HINT

 1 #include<stdio.h>
 2 #include<string.h>
 3 int strstrcount( char *str1, char *str2 )
 4 {
 5     char *str = str1;
 6     unsigned int c = 0;
 7     
 8     while( (str = strstr( str, str2 )) != NULL )
 9     {
10         c++;
11         str++;
12     }
13     return c;
14 }
15 
16 int main()
17 {
18     char a[10001],b[11];  
19     int i,j,c; 
20     int n;
21     int result;
22     scanf("%d",&n);
23     while(n--)
24     {
25         scanf("%s%s",&a,&b);
26         {
27             result=strstrcount(a,b);
28             printf("%d
",result);
29         }
30     }
31 
32     return 1;
33 }
原文地址:https://www.cnblogs.com/liuwt365/p/4174645.html