查找字串出现的次数
交谈中请勿轻信汇款、中奖信息、陌生电话,勿使用外挂软件。INSIST ON(303451715) 11:00:05
题目描述
We hate WA! We hate TLE! We hate RE! We hate PE......! The only thing we love is AC!Because we are ACMers! Now we give you a task that you should find how many strings―"AcmersLoveAc" are there in a string that we input.
输入
The input contains several testcases. Each testcase consists of one string(only contains capital letter and Lowercase letter) which is at most 100 characters. Input is terminated by EOF.
输出
For each testcase output, print an integer which stands for that how many strings―"AcmersLoveAc" are there in the input
string.
样例输入
IKnowAcmersLoveAc
AcmersDontLoveAc
AcmersLoveAcAndAcmersLoveAc
样例输出
1
0
2
#include <stdio.h>
#include <string.h>
int strstrcount(char *str1,char *str2 )
{
char *str=str1;
int c=0;
while((str=strstr(str,str2))!=NULL)
{
c++;
str++;
}
return c;
}
int main()
{
char a[13]="AcmersLoveAc";
char b[100];
int h;
while(scanf("%s",b)!=EOF)
{
h=strstrcount(b,a);
printf("%d\n",h);
}
return 0;
}
运行没错,但往ACM上提交的时候说运行错误,是什么原因啊,麻烦告诉我下,谢谢了