题意:给一个时间,求三个时针之间的夹角,分数表示。
解法:算算算。统一了一下分母。
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
int main()
{
int T;
while(~scanf("%d", &T))
{
while(T--)
{
int hh, mm, ss;
scanf("%d:%d:%d", &hh, &mm, &ss);
int hs = hh * 3600 + mm * 60 + ss;
int ms = mm * 60 + ss;
ms *= 12;
ss *= 120 * 6;
hs %= 43200;
ms %= 43200;
ss %= 43200;
int hhmm = abs(hs - ms);
if(hhmm > 120 * 180)
hhmm = 120 * 360 - hhmm;
int hhss = abs(hs - ss);
if(hhss > 120 * 180)
hhss = 120 * 360 - hhss;
int mmss = abs(ms - ss);
if(mmss > 120 * 180)
mmss = 120 * 360 - mmss;
int r = __gcd(hhmm, 120);
if(r == 120 || hhmm == 0)
printf("%d", hhmm / 120);
else
printf("%d/%d", hhmm / r, 120 / r);
r = __gcd(hhss, 120);
if(r == 120 || hhss == 0)
printf(" %d", hhss / 120);
else
printf(" %d/%d", hhss / r, 120 / r);
r = __gcd(mmss, 120);
if(r == 120 || mmss == 0)
printf(" %d ", mmss / 120);
else
printf(" %d/%d ", mmss / r, 120 / r);
puts("");
}
}
return 0;
}