Question:
Five time hh: mm are given, which are sorted by the angle between the hour and the minute hand, and the output time is in the middle (third. (0 <= hh <= 23,0 <= mm <= 59)
Analysis:
The problem is to find at any time.Clock Angle. It's very easy. I wrote the code and submitted it soon, wa ......
After being depressed for a long time, I finally spent 10 yuan of gold coins on the Hengyang 8 th Chinese forum and read other people's code to find myself making a low-level mistake ......
If the split needle is not at 0, the hour hand is not at the hour.
Bytes --------------------------------------------------------------------------------------------
/*
Zju2680 clock
*/
# Include <stdio. h>
# Include <stdlib. h>
# Define N 5
# Define PE 0.000001
Typedef struct {
Int H, M;
} Time;
Time A [n];
Inline double ABS (Double X ){
Return x> 0? X:-X;
}
Double toangle (time t ){
Double CH = (T. H <12? T. H: T. h-12)/12.) * 360. + (T. M/60.) * 30 .;
Double CM = (T. M/60.) * 360 .;
Double angle = ABS (ch-cm );
If (angle> 180.) return 360-angle;
Else return angle;
}
Int cmp2 (Time a, Time B ){
If (a. h = B. h) return a. m-b.m;
Else return a. h-b.h;
}
Int cmp (const void * A, const void * B ){
Double angA = toAngle (* (Time *) );
Double angB = toAngle (* (Time *) B );
If (angA <angB-PE) return-1;
If (angA> angB + PE) return 1;
Return cmp2 (* (Time *) A, * (Time *) B );
}
Int main ()
{
Int I, j, k, m, n, T;
Scanf ("% d", & T );
While (t --){
// Input
For (I = 0; I <n; I ++)
Scanf ("% d: % d", & A [I]. H, & A [I]. m );
// Sort
Qsort (A, N, sizeof (time), CMP );
// Output
Printf ("% 02d: % 02d/N", a [2]. H, a [2]. m );
}
Return 0;
}