Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 53 Accepted Submission(s): 34
Problem Description
Give a time.(hh:mm:ss),you should answer the angle between any two of the minute.hour.second hand
Notice that the answer must be not more 180 and not less than 0
Notice that the answer must be not more 180 and not less than 0
Input
There are
T
(1≤T≤104)
test cases
for each case,one line include the time
0≤hh<24 , 0≤mm<60 , 0≤ss<60
for each case,one line include the time
0≤hh<24 , 0≤mm<60 , 0≤ss<60
Output
for each case,output there real number like A/B.(A and B are coprime).if it's an integer then just print it.describe the angle between hour and minute,hour and second hand,minute and second hand.
Sample Input
4 00:00:00 06:00:00 12:54:55 04:40:00
Sample Output
0 0 0 180 180 0 1391/24 1379/24 1/2 100 140 120Hint每行输出数据末尾均应带有空格
Source
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
const int mui=24000;
int gcd(int m,int n)
{
return n ? gcd(n,m%n):m;
}
void print(int x)
{
if(x==0)
{
printf("0 ");
return;
}
int ans = gcd(x,mui);
int a,b;
a = x / ans;
b = mui / ans;
if(b==1)
{
printf("%d ",a);
}
else
{
printf("%d/%d ",a,b);
}
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int hh,mm,ss;
scanf("%d:%d:%d", &hh, &mm, &ss);
if(hh>=12) hh -= 12;
int j1,j2,j3;
j3 =mui * ss * 6;
j2 =mui * ss / 60 * 6 + mui * mm * 6;
j1 =mui * ss / 120 + mui * mm / 2 + mui * hh * 30;
int ans1,ans2,ans3;
ans1 = abs(j1-j2);
ans2 = abs(j1-j3);
ans3 = abs(j2-j3);
if(ans1 > mui *180) ans1 = mui *360 - ans1;
if(ans2 > mui *180) ans2 = mui *360 - ans2;
if(ans3 > mui *180) ans3 = mui *360 - ans3;
print(ans1);print(ans2);print(ans3);
printf("\n");
}
}