Skip to content

Commit 2b831c2

Browse files
ing-eokingbugs-bot
authored andcommitted
๐Ÿœ Study: ๊ด‘๊ณ  ์‚ฝ์ž…
1 parent d05c110 commit 2b831c2

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <vector>
4+
#include <sstream>
5+
6+
using namespace std;
7+
8+
int stot(string str) {
9+
istringstream iss(str);
10+
string buf;
11+
int d = 3600, t = 0;
12+
while (getline(iss, buf, ':')) {
13+
t += stoi(buf) * d;
14+
d /= 60;
15+
}
16+
return t;
17+
}
18+
19+
string ttos(int i) {
20+
string t, n;
21+
int d = 3600;
22+
while (d > 0) {
23+
n = to_string(i / d);
24+
i = i % d;
25+
d /= 60;
26+
t = t + ((n.length() % 2) ? "0" : "") + n + (d > 0 ? ":" : "");
27+
}
28+
return t;
29+
}
30+
31+
string solution(string play_time, string adv_time, vector<string> logs) {
32+
string answer = "", buf;
33+
int pt = stot(play_time);
34+
vector<long long> watch(pt + 1);
35+
for (auto l : logs) {
36+
istringstream iss(l);
37+
vector<int> t;
38+
while (getline(iss, buf, '-')) t.push_back(stot(buf));
39+
watch[t[0]]++;
40+
watch[t[1]]--;
41+
}
42+
for (int i = 1; i <= pt; i++) watch[i] += watch[i - 1];
43+
for (int i = 1; i <= pt; i++) watch[i] += watch[i - 1];
44+
int at = stot(adv_time), i_max = 0;
45+
long long _max = watch[at - 1];
46+
for (int i = 1; i + at - 1 <= pt; i++) {
47+
long long cur = watch[i + at - 1] - watch[i - 1];
48+
if (cur > _max) {
49+
_max = cur;
50+
i_max = i;
51+
}
52+
}
53+
return ttos(i_max);
54+
}

0 commit comments

Comments
ย (0)