Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
#include <limits.h>
#define debug "output for debug\n"
#define pi (acos(-1.0))
#define eps (1e-6)
#define inf (1<<28)
#define sqr(x) (x) * (x)
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
int gcd(int a,int b)
{
if(b==0)
return a;
return gcd(b,a%b);
}
void angle(int a,int b)
{
int num;
if(abs(a-b)>6*30*3600)
num=6*60*3600-abs(a-b);
else
num=abs(a-b);
if(num%3600)
{
int d=gcd(num,3600);
printf("%d/%d ",num/d,3600/d);
}
else
printf("%d ",num/3600);
}
int main()
{
int i,j,k,h,m,s,t;
char c;
scanf("%d",&t);
while(t--)
{
scanf("%d%c%d%c%d",&h,&c,&m,&c,&s);
if(h>=12)
h=h-12;
//时针、分针、秒针都统一化为相同刻度3600*360
int ss=3600*s*6;
int mm=(60*s+3600*m)*6;
int hh=((s+60*m)*5+h*3600*5)*6;
angle(hh,mm);
angle(hh,ss);
angle(mm,ss);
printf("\n");
}
return 0;
}