题目:
Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 709 Accepted Submission(s): 452
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每行输出数据末尾均应带有空格
Author
SXYZ
Source
题意:给一个时间,求出时针,分针,秒针两两之间的夹角。
思路:把时针,分针,秒针的角度都求出来即可,时针的角度等于(hh+mm/60+ss/3600)*30,分针的角度等于(mm+ss/60)*6,秒针的角度为6*ss,需要注意的是,数据用分数表示,所以两两求差的时候也应该是分数相减,然后求GCD使他们互质。当大于180°时用360°减去它。
代码:
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include<climits>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,x,n) for(int i=x;i<(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define FORD(i,h,l) for(int i=(h);i>=(l);--i)
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define OI(X) printf("%d",X);
#define RS(X) scanf("%s", (X))
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define Swap(a, b) (a ^= b, b ^= a, a ^= b)
#define Dpoint strcut node{int x,y}
#define cmpd int cmp(const int &a,const int &b){return a>b;}
/*#ifdef HOME
freopen("in.txt","r",stdin);
#endif*/
const int MOD = 1e9+7;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
//#define HOME
int Scan()
{
int res = 0, ch, flag = 0;
if((ch = getchar()) == '-') //判断正负
flag = 1;
else if(ch >= '0' && ch <= '9') //得到完整的数
res = ch - '0';
while((ch = getchar()) >= '0' && ch <= '9' )
res = res * 10 + ch - '0';
return flag ? -res : res;
}
/*----------------PLEASE-----DO-----NOT-----HACK-----ME--------------------*/
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{int T;
RI(T);
char str[10];
while(T--)
{
scanf("%s",str);
int hh=0,mm=0,ss=0;
hh=(str[0]-'0')*10+str[1]-'0';
mm=(str[3]-'0')*10+str[4]-'0';
ss=(str[6]-'0')*10+str[7]-'0';
hh=hh%12;
int h1=3600*hh-660*mm-11*ss;
if(h1<0)
h1=-h1;
int h2=120;
int g1=gcd(h1,h2);
h1/=g1;
h2/=g1;
if(h1>h2*180)
{h1=360*h2-h1;
g1=gcd(h1,h2);
h1/=g1;
h2/=g1;}
if(h2==1)
printf("%d ",h1);
else
printf("%d/%d ",h1,h2);
int s1=3600*hh+60*mm+ss-720*ss;
if(s1<0)
s1=-s1;
int s2=120;
int g3=gcd(s1,s2);
s1/=g3;
s2/=g3;
if(s1>s2*180)
{s1=360*s2-s1;
g3=gcd(s1,s2);
s1/=g3;
s2/=g3;}
if(s2==1)
printf("%d ",s1);
else
printf("%d/%d ",s1,s2);
int m1=60*mm-59*ss;
int m2=10;
if(m1<0)
m1=-m1;
int g2=gcd(m1,m2);
m1/=g2;
m2/=g2;
if(m1>m2*180)
{
m1=360*m2-m1;
g2=gcd(m1,m2);
m1/=g2;
m2/=g2;}
if(m2==1)
printf("%d \n",m1);
else
printf("%d/%d \n",m1,m2);
}
return 0;
}