Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 328 Accepted Submission(s): 225
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
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
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 120
Source
2015 Multi-University Training Contest 8
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int gcd(int a,int b){
if(b == 0) return a;
return gcd(b,a%b);
}
void work(int a,int b){
int u = 120*360;
int f = ((a-b)%u+u)%u;
f = min(f,u-f);
u = 120;
int g = gcd(f,u);
u /= g;
f /= g;
if(u == 1) printf("%d ",f);
else printf("%d/%d ",f,u);
}
int main(){
int t,h,m,s;
scanf("%d",&t);
while(t--){
scanf("%d:%d:%d",&h,&m,&s);
h = h*60*60+m*60+s;
m = m*12*60+s*12;
s = s*12*60;
work(h,m);
work(h,s);
work(m,s);
printf("\n");
}
return 0;
}