-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path10138-CDVII.cpp
46 lines (45 loc) · 1.52 KB
/
10138-CDVII.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
#include <bits/stdc++.h>
using namespace std;
struct Record{
int month, day, hour, mins, loc;
bool isExit;
int getTime(){
return mins + hour*60 + day*24*60;
}
};
int main() {
int t;
string in;
scanf("%d\n\n",&t);
while(t--){
int fares[24] = {};
map<string,vector<Record>> licenseToRecord;
for(int i=0;i<24;i++) scanf("%d",fares+i);
cin.ignore();
while(getline(cin,in), !in.empty()){
istringstream iss(in);
string plate, command;
char ignore;
Record r;
iss >> plate >> r.month >> ignore >> r.day >> ignore >> r.hour >> ignore >> r.mins >> command >> r.loc;
r.isExit = command == "exit";
licenseToRecord[plate].push_back(r);
}
for(auto& p : licenseToRecord){
sort(p.second.begin(), p.second.end(),[](Record a, Record b){
return a.getTime() < b.getTime();
});
int totalCents = 200;
// consecutive match then add to cost
for(int i=0;i<p.second.size();i++)
if(!p.second[i].isExit && i+1 < p.second.size() && p.second[i+1].isExit){
int dist = abs(p.second[i].loc - p.second[i+1].loc);
totalCents += dist*fares[p.second[i].hour];
totalCents += 100;
}
if(totalCents != 200)
cout << p.first << " $" << setprecision(2) << fixed << totalCents/100.0 << endl;
}
if(t) cout << endl;
}
}