2024年蓝桥杯C++研究生组1T

题目
在这里插入图片描述
log文件内容
在这里插入图片描述
知识点:

  • 文件读取
  • 字符串分割

坑点:
超时情况count置1 而不是0

#include<iostream>
#include<fstream>
#include <string>
#include <sstream>
using namespace std;
int main(){
	ifstream ifs;
    string buf; 
	string s[4];
	int count=0;
	int t1,t2,max;
	ifs.open("22.txt",ios::in);
	if (!ifs.is_open()){
		cout << " can't open this file'"<<endl;
	}
	while(getline(ifs,buf)){

		s[0]=buf.substr(0,1);
		s[1]=buf.substr(2,1);
		s[2]=buf.substr(10);//前几位时间都一样 
		istringstream ss(s[2]);
   		ss >> t2;
   		if (s[0]==s[1]){
   			if((t2-t1)<=1000){
   				count ++;
			   }else{
					if(count>max){
						max=count;
						count=1;
					}
				}
		}else{
			if(count>max){
				max=count;
				count=0;
			}
		}
   		t1=t2;	
	} 
	cout << max << endl;
	ifs.close();
}
	
	
	
	

答案应该是9,答案所在位置大概是log文件的1171行

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值