|
发表于 2021-9-3 20:49:51
|
显示全部楼层
- #define SIZE 81
- int main()
- {
- char temp[SIZE] = "chi1 huo3 guo1";
- char ch;
- int count_message = 0,count_keyMessage = 0;
- int first_appearance = 0;//记录第一次出现关键句的位置
- int i;
- while((ch=getchar())!='.')
- {
- i = 1;
- if(ch=='c')//读到可能是吃火锅的字符
- {
- while(i<=13)//逐个字符与关键字符串进行比较
- {
- ch = getchar();
- if(ch != temp[i])
- break;
- i++;
- }
- if(i>13)//说明与关键字符串一致
- {
- count_keyMessage++;
- if(!first_appearance)//说明第一次出现
- first_appearance = count_message + 1;
- }
- }
- else if(ch=='\n')
- count_message++;
- }
- printf("%d\n",count_message);
- if(count_keyMessage)
- printf("%d %d\n",first_appearance,count_keyMessage);
- else
- printf("-_-#\n");
- return 0;
- }
复制代码 |
|