一道看着高大上其实很水很水的题
求时针分针角度,然后排序,输出中间的那个
1.找出时针分针和 12 的距离,然后一减就行了
2.如果角度大于180度,就取补角
3.常规知识,自己可以推的,分针 *1 = 6°,时针 *1 = 30°,分针动时针也会动,找好关系
4.用double 类型变量 因为有0.5°的出现
1094.Clock
Description
There is an analog clock with two hands: an hour hand and a minute hand. The two hands form an angle. The angle is measured as the smallest angle between the two hands. The angle between the two hands has a measure that is greater than or equal to 0 and less than or equal to 180 degrees.
Given a sequence of five distinct times written in the format hh : mm , where hh are two digits representing full hours (00 <= hh <= 23) and mm are two digits representing minutes (00 <= mm <= 59) , you are to write a program that finds the median, that is, the third element of the sorted sequence of times in a nondecreasing order of their associated angles. Ties are broken in such a way that an earlier time precedes a later time.
For example, suppose you are given a sequence (06:05, 07:10, 03:00, 21:00, 12:55) of times. Because the sorted sequence is (12:55, 03:00, 21:00, 06:05, 07:10), you are to report 21:00.
Given a sequence of five distinct times written in the format hh : mm , where hh are two digits representing full hours (00 <= hh <= 23) and mm are two digits representing minutes (00 <= mm <= 59) , you are to write a program that finds the median, that is, the third element of the sorted sequence of times in a nondecreasing order of their associated angles. Ties are broken in such a way that an earlier time precedes a later time.
For example, suppose you are given a sequence (06:05, 07:10, 03:00, 21:00, 12:55) of times. Because the sorted sequence is (12:55, 03:00, 21:00, 06:05, 07:10), you are to report 21:00.
Input
The input consists of T test cases. The number of test cases (T) is given on the first line of the input file. Each test case is given on a single line, which contains a sequence of five distinct times, where times are given in the format hh : mm and are separated by a single space.
Output
Print exactly one line for each test case. The line is to contain the median in the format hh : mm of the times given. The following shows sample input and output for three test cases.
Sample Input
3 00:00 01:00 02:00 03:00 04:00 06:05 07:10 03:00 21:00 12:55 11:05 12:05 13:05 14:05 15:05
Sample Output
02:00 21:00 14:05
临近考试水一水,身心健康。。#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> #include <queue> #include <map> #include <vector> #include <set> using namespace std; struct time{ double h; double m; double hm; char s[6]; }tim[10010]; bool cmp(time a, time b) { if(a.hm < b.hm)return 1; if(a.hm > b.hm)return 0; if(a.hm == b.hm&& a.h != b.h)return a.h < b.h; else return a.m < b.m; } int main() { int t; int a, b; cin>>t; while(t--) { for(int i = 0; i < 5; i ++) { tim[i].h = 0; tim[i].m = 0; tim[i].hm = 0; } for(int i = 0; i < 5; i ++) { cin>>tim[i].s; a = (tim[i].s[0] - '0')*10 + (tim[i].s[1] - '0') * 1; b = (tim[i].s[3] - '0')*10 + (tim[i].s[4] - '0') * 1; tim[i].h = (a % 12) * 30 + b * 0.5; tim[i].m = b * 6; tim[i].hm = fabs(tim[i].h - tim[i].m); if(tim[i].hm > 180)tim[i].hm = 360 - tim[i].hm; //cout<<tim[i].h<<' '<<tim[i].m<<' '<<tim[i].hm<<endl; } sort(tim, tim + 5, cmp); //for(int i = 0; i < 5; i ++)cout<<tim[i].h<<' '<<tim[i].m<<' '<<tim[i].hm<<endl; cout<<tim[2].s<<endl; } return 0; }