吃火锅

# include <iostream>
# include<algorithm> 
# include<cstring>
using namespace std;
 
int main(){
	//char a[90];
	string a;
	string d = "chi1 huo3 guo1";
	string c1;
	int f=0;//id只需要被更新一次 
	int c = 0;//记录有多少条信息 
	int cnt=0;//记录有几次吃火锅 
	int id=0;  //记录第一个吃火锅的下标 
	while(1){
		//cin.getline(a,90);//不可以 
		getline(cin,a);//可以用于字符串 
		//if(strcmp(a,".")==0){
		//	break;
		//}
		if(a == ".") break;
		c++;
		int z=0;
		//if(strstr(a,"chi1 huo3 guo1")!=NULL){
			//cout<<strstr(str,"chi1 huo3 guo1")<<endl;
			for(int i=0;a[i];i++){
				z=0;
				if(a[i]=='c'){
					c1=a.substr(i,14);//要将字符串的一部分赋给另一个字符串用substr,i是位置,14是截取几个字符 
					/*for(int j=i;j<=i+13;j++){
						c1[z++] = a[j];不能这么做 
					}*/
					//cout<<"*"<<c1<<endl;
					
					//确定是chi1 huo3 guo1 
					if(c1==d){
						cnt++;
						if(cnt==1&&f==0){
							id = c;   //第一次的吃火锅 
							f=1;
						}
						break; 
					}
					//i = i+13; 
				}
			}
		
		} 
	//}
	cout<<c<<endl;
	if(cnt==0){
		cout<<"-_-#"<<endl;
	}
	else
	cout<<id<<' '<<cnt<<endl;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值