-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
112 lines (95 loc) · 3.19 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <map>
using namespace std;
int main(){
//日志行数
int N;
//日志集合
vector<vector<string>> logArray;
while(cin>>N){
for(size_t i=0;i<N;++i){
vector<string> curLog;
string time;
string hostID;
string log_text;
cin>>time>>hostID>>log_text;
curLog.push_back(time);
curLog.push_back(hostID);
curLog.push_back(log_text);
logArray.push_back(curLog);
}
//查询次数
int T;
cin>>T;
for(int _i=0;_i<T;++_i){
vector<string> resultArray;
//存放命令与参数的map
map<string,string> orderMap;
int orderNum;
cin>>orderNum;
while(orderNum--){
string orderType;
string orderArg;
cin>>orderType>>orderArg;
orderMap[orderType]=orderArg;
}
string findRes=orderMap["--search"];
string hostID="";
if(orderMap.find("--hostid")!=orderMap.end()){
hostID=orderMap["--hostid"];
}
size_t i=0;
if(hostID==""){
for(i=0;i<logArray.size();++i){
if(logArray[i][2].find(findRes)!=std::string::npos){
break;
}
}
}else{
for(i=0;i<logArray.size();++i){
if(logArray[i][2].find(findRes)!=std::string::npos&&logArray[i][1]==hostID){
break;
}
}
}
if(i==logArray.size()){
//Do Nothing
}else{
int before=3000;
if(orderMap.find("--before")!=orderMap.end()){
before=atoi(orderMap["--before"].data());
}
int after=3000;
if(orderMap.find("--after")!=orderMap.end()){
after=atoi(orderMap["--after"].data());
}
if(before==3000&&after==3000){
resultArray.push_back(logArray[i][2]);
}
else{
if(before!=3000){
int start=0>i-before+1?0:i-before;
for(;start<i;++start)
resultArray.push_back(logArray[start][2]);
}
resultArray.push_back(logArray[i][2]);
if(after!=3000){
int end=logArray.size()-1<i+after?logArray.size()-1:i+after;
for(int j=i+1;j<=end;++j)
resultArray.push_back(logArray[j][2]);
}
}//end of else
}//end of else
if(resultArray.empty())
std::cout<<"ERROR"<<std::endl;
else{
for(string curString:resultArray)
std::cout<<curString<<std::endl;
}
}
}
return 0;
}