-
Notifications
You must be signed in to change notification settings - Fork 0
/
A1016-1.cpp
97 lines (91 loc) · 2.15 KB
/
A1016-1.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
/*
* author: zhouyuhao
* created: 2024-04-26 16:27:30
* modified: 2024-04-26 17:00:00
* item: Programming Ability Test
* site: 914, Harbin
*/
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
struct per {
string name;
int M, d, h, m, t;
string line;
};
int toll[25];
double calfare(per a, per b) {
double fare = (b.d - a.d) * toll[24] * 60;
int flag = 1;
if (a.h * 60 + a.m > b.h * 60 + b.m) {
swap(a, b);
flag = -1;
}
for (int i = a.h + 1; i < b.h; i++) {
fare += flag * toll[i] * 60;
}
if (a.h == b.h) {
fare += flag * (b.m - a.m) * toll[a.h];
} else {
fare += flag * (60 - a.m) * toll[a.h];
fare += flag * b.m * toll[b.h];
}
return fare;
}
int main(int argc, char const *argv[]) {
for (int i = 0; i < 24; i++) {
cin >> toll[i];
toll[24] += toll[i];
}
int n;
cin >> n;
vector<per> p(n);
for (int i = 0; i < n; i++) {
cin >> p[i].name;
int unused __attribute__((unused)) = 0;
unused = scanf("%d:%d:%d:%d", &p[i].M, &p[i].d, &p[i].h, &p[i].m);
p[i].t = p[i].d * 24 * 60 + p[i].h * 60 + p[i].m;
cin >> p[i].line;
}
sort(p.begin(), p.end(), [](per a, per b) -> bool {
if (a.name != b.name) {
return a.name < b.name;
} else {
return a.t < b.t;
}
});
vector<per> b;
for (int i = 0; i < n; i++) {
if (p[i].name == p[i + 1].name) {
if (p[i].line == "on-line" && p[i + 1].line == "off-line") {
b.emplace_back(p[i]);
b.emplace_back(p[i + 1]);
}
}
}
double tf = 0;
for (int i = 0; i < (int)b.size(); i += 2) {
bool next = false, before = false;
if (i + 2 < (int)b.size() && b[i + 2].name == b[i].name) {
next = true;
}
if (i - 2 >= 0 && b[i - 2].name == b[i].name) {
before = true;
}
if (!before) {
cout << b[i].name << " " << setfill('0') << setw(2) << b[i].M << "\n";
}
printf("%02d:%02d:%02d ", b[i].d, b[i].h, b[i].m);
printf("%02d:%02d:%02d ", b[i + 1].d, b[i + 1].h, b[i + 1].m);
double f = calfare(b[i], b[i + 1]) / 100;
cout << b[i + 1].t - b[i].t << " $" << fixed << setprecision(2) << f << "\n";
tf += f;
if (!next) {
cout << "Total amount: $" << fixed << setprecision(2) << tf << "\n";
tf = 0;
}
}
return 0;
}