| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 630 人关注过本帖
标题:查找字串出现的次数
只看楼主 加入收藏
z6439186
Rank: 1
等 级:新手上路
帖 子:16
专家分:2
注 册:2011-11-15
结帖率:33.33%
收藏
已结贴  问题点数:20 回复次数:2 
查找字串出现的次数
交谈中请勿轻信汇款、中奖信息、陌生电话,勿使用外挂软件。

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上提交的时候说运行错误,是什么原因啊,麻烦告诉我下,谢谢了

搜索更多相关主题的帖子: 外挂软件 several capital Because only 
2012-09-07 11:20
遗矢的老人
Rank: 9Rank: 9Rank: 9
来 自:成都
等 级:蜘蛛侠
威 望:7
帖 子:325
专家分:1131
注 册:2012-7-20
收藏
得分:10 
睡醒了就随便看看,习惯想法是没问题的,就是题目的意思好像没包含死循环,他意思好像就在终端输入小于100个字符的字符串就可以了,我没玩过那个,你改了再试试啊
2012-09-08 01:55
l921926934
Rank: 2
等 级:论坛游民
帖 子:1
专家分:10
注 册:2012-9-10
收藏
得分:10 
char b[100];该成char b[105];
2012-09-10 10:41
快速回复:查找字串出现的次数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014202 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved