您的位置:首页 > 其它

杭电OJ 5387 Clock

2015-08-17 11:04 232 查看


Clock

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 529 Accepted Submission(s): 356



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
Hint每行输出数据末尾均应带有空格此题首先要弄清分 秒 时三者之间的关系。然后我是计算它们三者到12点钟方向的角度,它们三者角度差的绝对值就是它们之间的角度。当然,由于题目特殊要求,记录数据我是用分子分母两个部分记录。同时求最大公约数的函数用递归貌似会出现“爆栈”的问题,所以没用递归实现。#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
using namespace std;

long long T;
long long H,M,S;
long long SM,SZ,MM,MZ,HM,HZ;
char c,s[10];
long long t,mom,son;

long long gcd(long long a,long long b)
{

long long tt;
if(a<b) swap(a,b);
//return b==0?a:gcd(b,a%b);

while(b)
{
tt=a;
a=b;
b=tt%b;
}
return a;

}

int main()
{
while(cin>>T)
{
while(T--)
{
cin>>s;
H=(*s-'0')*10 + s[1]-'0';
M=(s[3]-'0')*10 + s[4]-'0';
S=(s[6]-'0')*10 + s[7]-'0';

if(H>=12) H-=12;   //=12也要减哦

SZ=S*6;
SM=1;                 //cout<<SM<<" "<<SZ<<endl;///////

//t=gcd(10,S);
//MZ=M*6;
MZ=60*M+S;
MM=10;   //cout<<MM<<" "<<MZ<<endl;///////
t=gcd(MZ,MM);
MM/=t;
MZ/=t;

//HZ=H*30;
HM=120;
HZ=3600*H + 60*M + S;      //cout<<HM<<" "<<HZ<<endl;///////
t=gcd(HM,HZ);
HZ/=t;
HM/=t;

mom = HM*MM;
son = abs(HZ*MM - MZ*HM);
if(son>180*mom) {son=360*mom - son;}
t=gcd(son,mom);
if(son%mom == 0) cout<<son/mom<<" ";
else cout<<(son)/t<<"/"<<(mom)/t<<" ";

mom = HM*SM;
son = abs(HZ*SM - SZ*HM);
if(son>180*mom) {son=360*mom - son;}
t=gcd(son,mom);
if(son%mom == 0) cout<<son/mom<<" ";
else cout<<(son)/t<<"/"<<(mom)/t<<" ";

mom = MM*SM;
son = abs(MZ*SM - SZ*MM);
if(son>180*mom) {son=360*mom - son;}
t=gcd(son,mom);
if(son%mom == 0) cout<<son/mom<<" ";
else cout<<(son)/t<<"/"<<(mom)/t<<" ";  //

cout<<endl;

}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: