ZJU2680-Clock angle of Clock at any time

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.