题目:https://pintia.cn/problem-sets/994805046380707840/exam/problems/1336215880692482053?type=7&page=0
直达站
题目照片
思路:本题有几个重点:第一个是输出总条数不知道 只能用gets输入 结束的时候判断是否这一次输出strlen==1且是’.'即可。第二个是运用strstr函数 判断这一语句里是否有chihuoguo这一语句(一开始想用strcmp,但始终有答案点错误情况)需要定义:首次出现chihuoguo;chihuoguo前边有多少行;有几个chihuoguo。
代码块
#include<stdio.h>
#include<string.h>
int main()
{
char a[90];
int all=0,count=0,c=0;
char b[15]="chi1 huo3 guo1";//预准备chihuoguo,等待比较
while(1)
{
gets(a);
if(a[0]=='.'&&strlen(a)==1)//是否是.
break;
else {
all++;
if(strstr(a,b)!=NULL)//strstr函数,判断是否这一句中有指定的某个片段语句
{
count++;
if(count==1)//记录首次出现
c=all;
}
}
}
printf("%d\n",all);
if(count>0)
printf("%d %d",c,count);
else if(count==0) printf("-_-#");
return 0;
}
- 可以尝试一下strcmp怎么写 然后告诉我 谢谢啦