Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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每行输出数据末尾均应带有空格
暴力即可,我是先求出时针、分针、秒针的角度,化简为分母为120的分数,然后大角度减小角度,超过360度,减360,大于180度,用360减去原角度,通分输出即可。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a,b,c;
scanf("%d:%d:%d",&a,&b,&c);
if(a>12)
{
a-=12;
}
int num1=(60*b+c+3600*a);
int num2=(12*c+720*b);
int num3=(720*c);
int ans1;
int ans2;
int ans3;
if(num1>num2)
{
ans1=num1-num2;
}
else
{
ans1=num2-num1;
}
//cout<<num1<<" "<<num2<<" "<<num3<<endl;
if(num1>num3)
{
ans2=num1-num3;
}
else
{
ans2=num3-num1;
}
if(num2>num3)
{
ans3=num2-num3;
}
else
{
ans3=num3-num2;
}
if(ans1>360*120)
{
ans1=-360*120+ans1;
}
if(ans2>360*120)
{
ans2=-360*120+ans2;
}
if(ans3>360*120)
{
ans3=-360*120+ans3;
}
//cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
if(ans1>180*120)
{
ans1=360*120-ans1;
}
if(ans2>180*120)
{
ans2=360*120-ans2;
}
if(ans3>180*120)
{
ans3=360*120-ans3;
}
//cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
int gcd1=__gcd(ans1,120);
int gcd2=__gcd(ans2,120);
int gcd3=__gcd(ans3,120);
if(gcd1==120)
{
printf("%d ",ans1/120);
}
else
{
printf("%d/%d ",ans1/gcd1,120/gcd1);
}
if(gcd2==120)
{
printf("%d ",ans2/120);
}
else
{
printf("%d/%d ",ans2/gcd2,120/gcd2);
}
if(gcd3==120)
{
printf("%d ",ans3/120);
}
else
{
printf("%d/%d ",ans3/gcd3,120/gcd3);
}
printf("\n");
}
return 0;
}