题目
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行