-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path10191.cpp
More file actions
87 lines (80 loc) · 1.2 KB
/
10191.cpp
File metadata and controls
87 lines (80 loc) · 1.2 KB
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
#include<stdio.h>
#include<algorithm>
using namespace std;
struct ss
{
long h1,m1,h2,m2;
}T[110];
bool cmp(ss aa,ss bb)
{
if(aa.h1>bb.h1)
return false;
else if(aa.h1==bb.h1)
{
if(aa.m1>bb.m1)
return false;
}
return true;
}
int main()
{
long i,k=1,u,top,mx,h,m,n,dh,dm,fg;
char c;
while(~scanf("%ld",&n))
{
fg=1;
mx=0;
for(i=0;i<n;i++)
{
scanf("%ld%c%ld%ld%c%ld",&T[i].h1,&c,&T[i].m1,&T[i].h2,&c,&T[i].m2);
c=getchar();
while(c!='\n')
c=getchar();
}
sort(T,T+n,cmp);
for(i=0;i<n;i++)
{
if(fg)
{
fg=0;
top=(T[i].h1*60+T[i].m1)-600;
u=T[i].h2*60+T[i].m2;
if(top>mx)
{
mx=top;
h=10;
m=0;
}
continue;
}
top=(T[i].h1*60+T[i].m1)-u;
if(top>mx)
{
mx=top;
h=u/60;
m=u%60;
}
u=T[i].h2*60+T[i].m2;
}
if(1080-u>mx)
{
mx=1080-u;
h=u/60;
m=u%60;
}
dh=mx/60;
dm=mx%60;
if(n==0)
{
dh=8;
dm=0;
h=10;
m=0;
}
if(dh!=0)
printf("Day #%ld: the longest nap starts at %02ld:%02ld and will last for %ld hours and %ld minutes.\n",k++,h,m,dh,dm);
else
printf("Day #%ld: the longest nap starts at %02ld:%02ld and will last for %ld minutes.\n",k++,h,m,dm);
}
return 0;
}