ACM~java~web~密码学

# hdu5387 钟表指针之间夹角

B - Clock
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Appoint description:

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  test cases
for each case,one line include the time

,,

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



1/120 度，那么我们将表盘看做一个坐标系，12点钟为起点，那么可以计算出每个指针这一刻的角度是多少，但是为了避免

，然后要化简为最简分式就可以了，（分子是120）

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
using namespace std;
int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
int main()
{
int h,m,s;
int H,M,S;
int ans1,ans2,ans3;
char str[20];
int t;
cin>>t;
while(t--)
{
cin>>str;
h=(str[0]-'0')*10+(str[1]-'0');
m=(str[3]-'0')*10+(str[4]-'0');
s=(str[6]-'0')*10+(str[7]-'0');
if(h>=12)
h-=12;

//cout<<h<<endl;
H=h*3600+m*60+s;
M=m*720+12*s;
S=s*720;

ans1=max(H,M)-min(H,M);
ans2=max(H,S)-min(H,S);
ans3=max(M,S)-min(M,S);

ans1=min(ans1,43200-ans1);
ans2=min(ans2,43200-ans2);
ans3=min(ans3,43200-ans3);

int g1,g2,g3;
g1=gcd(ans1,120);
g2=gcd(ans2,120);
g3=gcd(ans3,120);

ans1/=g1;
ans2/=g2;
ans3/=g3;

int f1,f2,f3;
f1=120/g1;
f2=120/g2;
f3=120/g3;

if(f1==1)
{
cout<<ans1<<" ";
}

else
{
if(ans1==0)
{
cout<<0<<" ";
}
else
cout<<ans1<<"/"<<f1<<" ";
}

if(f2==1)
{
cout<<ans2<<" ";
}

else
{
if(ans2==0)
cout<<0<<" ";
else
cout<<ans2<<"/"<<f2<<" ";
}

if(f3==1)
{
cout<<ans3<<" "<<endl;
}

else
{
if(ans3==0)
cout<<0<<" "<<endl;
else
cout<<ans3<<"/"<<f3<<" "<<endl;
}
}
return 0;
}

#### HDU5387

2015-08-17 20:52:49

#### hdu5387(模拟)

2015-08-13 16:47:12

#### hdu5387 Clock

2015-08-13 21:09:38

#### 时钟夹角

2017-04-18 17:10:41

#### java钟表时针分针夹角计算器

2017-10-06 22:44:57

#### 钟表的指针

2018-04-14 19:28:05

#### hdu5387 Clock(数学水题)

2015-08-28 21:51:10

#### hdu5387 模拟时钟

2015-08-14 07:39:27

#### HDU5387 Clock 时钟模拟

2015-08-14 09:45:13

#### 计算时钟的夹角

2015-03-23 16:07:34