Created
September 24, 2019 18:00
-
-
Save drstranges/c1932202c57fd49abe8f59673017771a to your computer and use it in GitHub Desktop.
Work time :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 | |
15.01. 17:00 | |
16.01. 12:00 | |
11.02. 14:00 | |
30.01. 10:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
using namespace std; | |
ifstream in("input.txt"); | |
ofstream out("output.txt"); | |
struct P { int d, m, t;}; | |
int s(const string &l, int s) { return stoi(l.substr(s, 2)); } | |
int main() { | |
int c, i; | |
string l; | |
in >> c; | |
P p[c]; | |
for (i = 0; i < c; ++i) { | |
in >> l; | |
p[i].d = s(l,0); | |
p[i].m = s(l,3); | |
in >> l; | |
p[i].t = s(l,0) * 60 + s(l,3); | |
} | |
qsort(p, c, sizeof(struct P), [](const void *s1, const void *s2) { | |
P *a = (P *) s1; | |
P *b = (P *) s2; | |
int r = a->m - b->m; | |
if (r == 0) r = a->d - b->d; | |
if (r == 0) r = a->t - b->t; | |
return r; | |
}); | |
int r = 0; | |
for (i = 0; i < c; i+=2) { | |
P s = p[i]; | |
P e = p[i+1]; | |
r += e.t - s.t + 1; | |
r += (e.d - s.d) * 480; | |
if (e.m != s.m) { | |
for (int m = s.m; m < e.m; m++) { | |
r += (m == 2 ? 28 : m % 2 == (m <= 7 ? 0 : 1) ? 30 : 31) * 480; | |
} | |
} | |
} | |
int h = r / 60; | |
int m = r - (h * 60); | |
out << h << (m > 9 ? ":" : ":0") << m; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
using namespace std; | |
ifstream in("input.txt"); | |
ofstream out("output.txt"); | |
struct Page { int day, month, minutes;}; | |
int compare(const void *s1, const void *s2) { | |
Page *a = (Page *) s1; | |
Page *b = (Page *) s2; | |
int r = a->month - b->month; | |
if (r == 0) r = a->day - b->day; | |
if (r == 0) r = a->minutes - b->minutes; | |
return r; | |
} | |
int parseInt(const string &l, int pos) { return stoi(l.substr(pos, 2)); } | |
int main() { | |
int c, i; | |
string l; | |
in >> c; | |
Page pages[c]; | |
for (i = 0; i < c; ++i) { | |
in >> l; | |
pages[i].day = parseInt(l, 0); | |
pages[i].month = parseInt(l, 3); | |
in >> l; | |
pages[i].minutes = parseInt(l, 0) * 60 + parseInt(l, 3); | |
} | |
qsort(pages, c, sizeof(struct Page), compare); | |
int r = 0; | |
for (i = 0; i < c; i+=2) { | |
Page p1 = pages[i]; | |
Page p2 = pages[i + 1]; | |
r += p2.minutes - p1.minutes + 1; | |
r += (p2.day - p1.day) * 480; | |
if (p2.month != p1.month) { | |
for (int m = p1.month; m < p2.month; m++) { | |
r += (m == 2 ? 28 : m % 2 == (m <= 7 ? 0 : 1) ? 30 : 31) * 480; | |
} | |
} | |
} | |
int hours = r / 60; | |
int minutes = r - (hours * 60); | |
out << hours << (minutes > 9 ? ":" : ":0") << minutes; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103:02 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment