Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 377 Accepted Submission(s): 200
Total Submission(s): 377 Accepted Submission(s): 200
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每行输出数据末尾均应带有空格
题意是给你时间,然后让你去算时针和分针的夹角,时针和秒针的夹角,分针和秒针的夹角,小于180的角
时针的夹角是 30*h +0.5*m + 0.5/60 *s;
分针的夹角 60×m + 0.1*s;
秒针的夹角 6*s;
大于 13:00:00 和 1:00:00 相同
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int gcd(int a, int b)
{
return b == 0 ? a:gcd(b,a%b);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int h, m, s;
scanf("%d:%d:%d",&h,&m,&s);
int ht, mt, st;
if(h >= 12)
h -=12;
ht = 18000*h+300*m + 5*s;
mt = 3600*m+60*s;
st = 3600*s;
int hm, hs, ms;
if(ht > mt)
hm = ht-mt;
else
hm = mt-ht;
if(360*600-hm<hm)
{
if(360*600-hm>0)
hm = 360*600-hm;
}
if(ht > st)
hs = ht-st;
else
hs = st-ht;
if(360*600-hs<hs)
{
if(360*600-hs > 0)
hs = 360*600-hs;
}
if(mt > st)
ms = mt - st;
else
ms = st - mt;
if(360*600-ms<ms)
{
if(360*600-ms>0)
ms = 360*600-ms;
}
if(hm%600==0)
{
printf("%d ",hm/600);
}
else
{
if(hm > 600)
printf("%d/%d ",hm/gcd(hm,600),600/gcd(hm,600));
else
printf("%d/%d ",hm/gcd(600,hm),600/gcd(600,hm));
}
if(hs%600==0)
{
printf("%d ",hs/600);
}
else
{
if(hs > 600)
printf("%d/%d ",hs/gcd(hs,600),600/gcd(hs,600));
else
printf("%d/%d ",hs/gcd(600,hs),600/gcd(600,hs));
}
if(ms%600==0)
{
printf("%d ",ms/600);
}
else
{
if(ms > 600)
printf("%d/%d ",ms/gcd(ms,600),600/gcd(ms,600));
else
printf("%d/%d ",ms/gcd(600,ms),600/gcd(600,ms));
}
printf("\n");
}
return 0;
}