-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1169.cpp
More file actions
58 lines (50 loc) · 1.84 KB
/
1169.cpp
File metadata and controls
58 lines (50 loc) · 1.84 KB
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
class Solution {
public:
struct tr{
string name;
int time;
int amt;
string city;
int k;
bool reported = false; //default is false
};
vector<string> naive (vector<string>& transactions) { //O(N^2), O(N log N) is possible but not necessary.
vector<tr> trs;
for(int k = 0; k < transactions.size(); k++){
stringstream s_stream(transactions[k]); //create string stream from the string
tr newtr; newtr.k = k;
int i = 0;
while(s_stream.good()) {
string substr;
getline(s_stream, substr, ','); //get first string delimited by comma
if(i == 0) newtr.name = substr;
if(i == 1) newtr.time = stoi(substr);
if(i == 2) newtr.amt = stoi(substr);
if(i == 3) newtr.city = substr;
i++;
}
trs.push_back(newtr);
}
vector<string> ans;
for(int i = 0; i < trs.size(); i++){
if(trs[i].amt > 1000){
trs[i].reported = true;
ans.push_back(transactions[trs[i].k]);
}
}
for(int i = 0; i < trs.size(); i++){
for(int j = i+1; j < trs.size(); j++){
if(trs[i].name == trs[j].name && trs[i].city != trs[j].city && abs(trs[i].time - trs[j].time) <= 60){
if(!trs[i].reported){
trs[i].reported = true;
ans.push_back(transactions[trs[i].k]);
} if(!trs[j].reported){
trs[j].reported = true;
ans.push_back(transactions[trs[j].k]);
}
}
}
}
return ans;
}
};