-
Notifications
You must be signed in to change notification settings - Fork 1
/
10_Parts_Rental.cpp
79 lines (62 loc) · 1.67 KB
/
10_Parts_Rental.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
#include<iostream>
#include<string>
#include<map>
using namespace std;
int monthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
struct user
{
string name;
int rentalTime;
};
int MonthToDay(int month)
{
if (month == 1)return 0;
int days = 0;
for (int i = 0; i < month - 1; i++)
days += monthDays[i];
return days;
}
int main()
{
ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);
int len;
int fine;
string sDuration;
int duration = 0;
map<string, map<string, user>> rentals;
map<string, long long> fineReports;
cin >> len >> sDuration >> fine;
duration += stoi(sDuration.substr(0, 3)) * 1440; // Day
duration += stoi(sDuration.substr(4, 2)) * 60; // Hour
duration += stoi(sDuration.substr(7, 2)); // Minute
for (int i = 0; i < len; i++)
{
string ymd, time, part, name;
int curTime = 0;
cin >> ymd >> time >> part >> name;
curTime += MonthToDay(stoi(ymd.substr(5, 2))) * 1440; // Month
curTime += stoi(ymd.substr(8, 2)) * 1440; // Day
curTime += stoi(time.substr(0, 2)) * 60; // Hour
curTime += stoi(time.substr(3, 2)); // Minute
// ´ë¿© ¸ñ·Ï¿¡¼ ã´Â´Ù¸é
if (rentals.find(part) != rentals.end() && rentals[part].find(name) != rentals[part].end())
{
int rentalDuration = curTime - rentals[part][name].rentalTime;
if (rentalDuration > duration)
{
fineReports[name] += (long long)((rentalDuration - duration) * fine);
}
rentals[part].erase(name);
if (rentals[part].empty())
rentals.erase(part);
}
else
rentals[part][name] = { name, curTime };
}
if (fineReports.empty()) cout << -1;
else
{
for (auto user : fineReports)
cout << user.first << " " << user.second << '\n';
}
}