hdu 1209 Clock(水题)

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 struct Time
 5 {
 6     int hour;
 7     int minute;
 8     int angle;
 9 };
10 double compute_angle(Time a)
11 {
12     if (a.hour >= 12)
13         a.hour -= 12;
14     int t = abs(a.hour*60 + a.minute - a.minute*12);         //乘以2避免浮点数运算
15     if (t > 360)
16     t = 720 - t;
17     return t;
18 }
19 bool cmp(Time t1, Time t2)
20 {
21     if (t1.angle != t2.angle)
22         return t1.angle < t2.angle;
23     else if (t1.hour != t2.hour)
24          return t1.hour < t2.hour;
25     else
26         return t1.minute < t2.minute;
27 }
28 int main()
29 {
30     int n;
31     scanf("%d", &n);
32     while (n--)
33     {
34         Time t[5];
35         for (int i = 0; i < 5; ++i)
36         {
37             scanf("%d:%d", &t[i].hour, &t[i].minute);
38             t[i].angle = compute_angle(t[i]);
39         }
40         std::sort(t, t + 5, cmp);
41         printf("%02d:%02d\n", t[2].hour, t[2].minute);
42     }
43     system("pause");
44     return 0;
45 }
原文地址:https://www.cnblogs.com/PegasusWang/p/3002745.html