Subject to the effect
Original title: http://uva.onlinejudge.org/external/5/579.pdf
background:
In general there are usually two clock pointers: hour, minute. The subject is telling you some sort, ask your program responds to the angle between the hour and minute hands. Please note: All of the perspective please respond to the smallest positive angle. For example: 9:00 is 90 degrees, -90 degrees is not, nor is 270 degrees.
Input:
Input is a series of time, each time a line appears in the following format: H: M.
1<= H <= 12 00<= M <=59
If time is 0:00 represents the input end. Note: H may be one or two digits, M is always 2 digits appear .. (That is, you see in the general electronic table mode. )
Output:
Please positive output corresponds to the minimum angle between the input time of the hour and minute hands. This angle should be between 0 to 180 degrees. Each output on a separate line. Each output to the third decimal place.
Sample Input
12:00 9:00 8:10 0:00
Sample Output
0.000 90.000 175.000
algorithm:
The idea is very simple as long as the hour and minute angle perspective of this moment are calculated, and then seek worse then the angle is the hour and minute hands.
Code:
Here attached my code, you can go here to submit your code to verify your code is correct.
View Code
1 #include<stdio.h> 2 #include<math.h> 3 int main(void) 4 { 5 double hour,min,a; 6 while(scanf("%lf:%lf",&hour,&min)!=EOF) 7 { 8 if(hour==0&&min==0)break; 9 hour=hour*30.0+min/60.0*30.0; 10 min=min*6.0; 11 a=fabs(hour-min); 12 if(a>180) 13 a=360-a; 14 printf("%0.3lf\n",a); 15 } 16 return 0; 17 }
Reproduced in: https: //www.cnblogs.com/qisong178878915/archive/2013/02/25/2932436.html