吃火锅啦

在这里插入图片描述2在这里插入图片描述在这里插入图片描述
字符串的处理问题,我还是迷迷糊糊:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<string.h>
using namespace std;
int main(){
    
    
	int num=0,a[110],b[110],n=0;
	char check[50]="chi1 huo3 guo1";
	while(1){
    
    
		char a[100];
		int i=0;
		cin.getline(a,110);//获取特定长度的数组字符串,不足 110 也会自动补 '\0' 
		if(a[0]=='.' && a[1]=='\0') break;
		num++;
		if(strstr(a,check)){
    
    
			b[num]++;
			n++;
		}
	}
	if(n==0) cout<<num<<endl<<"-_-#"<<endl;
	else{
    
    
		cout<<num<<endl;
		int flag;
		for(int i=1;i<=num;i++){
    
    
			if(b[i]==1){
    
    
				flag=i;break;
			}
		}
		cout<<flag<<' '<<n;
	}
	return 0;
}

cstring 头文件下的 strstr(str,substr) 函数,检查 substr 是否在 str 中,是的话输出 str 里从 substr 开始到 str 的结尾(bool 值为 true),否则什么都不输出(NULL)

猜你喜欢

转载自blog.csdn.net/interestingddd/article/details/115047819