2015 Multi-University Training Contest 7 Clock

2015 Multi-University Training Contest 7

Clock

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 468    Accepted Submission(s): 324

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

400:00:0006:00:0012:54:5504:40:00

 

 

Sample Output

0 0 0 180 180 0 1391/24 1379/24 1/2 100 140 120 

Hint

每行输出数据末尾均应带有空格

 

 

 

Author

SXYZ

 

 

Source

2015 Multi-University Training Contest 8

 

 

 

 

时针的转速为3600/120每小时=60/120每分钟=1/120每秒

分针的转速为720/120每分钟=12/120每秒

秒针的转速为720/120每秒

采用假分数且分母都为120的原因是为了便于计算,无需通分。

对于一个时间点,计算出每个针与12点方向的夹角,然后计算针之间的角度差,注意需保证夹角小于180度,而且,因为采用二十四小时计时法,所以需要考虑到小时数是否大于12.

最后计算的结果在输出之前需要转化为最简分数的形式,只需让分子分母都除以两者的最大公约数即可。

 

 

#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}
int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int h, m, s;
        scanf("%d:%d:%d", &h, &m, &s);
        if (h >= 12)
            h = h - 12;
        int shi, fen, miao;
        shi = 3600 * h + 60 * m + 1 * s;
        fen = 720 * m + 12 * s;
        miao = 720 * s;
        int shi_fen, shi_miao, fen_miao;
        shi_fen =abs(shi - fen);
        if (shi_fen > 21600)
            shi_fen = 43200 - shi_fen;
        shi_miao = abs(shi - miao);
        if (shi_miao > 21600)
            shi_miao = 43200 - shi_miao;
        fen_miao = abs(fen - miao);
        if (fen_miao > 21600)
            fen_miao = 43200 - fen_miao;
        int s11, s12, s21, s22, s31, s32;

        if (shi_fen == 0)
        {
            printf("%d ", 0);
        }
        else
        {
            s11 = shi_fen / gcd(shi_fen, 120);
            s12 = 120 / gcd(shi_fen, 120);
            if (s12==1)
                printf("%d ", s11);
            else
                printf("%d/%d ", s11,s12);
        }
        if (shi_miao == 0)
        {
            printf("%d ", 0);
        }
        else
        {
            s21 = shi_miao / gcd(shi_miao, 120);
            s22 = 120 / gcd(shi_miao, 120);
            if (s22 == 1)
                printf("%d ", s21);
            else
                printf("%d/%d ", s21, s22);
        }
        if (fen_miao == 0)
        {
            printf("%d \n", 0);
        }
        else
        {
            s31 = fen_miao / gcd(fen_miao, 120);
            s32 = 120 / gcd(fen_miao, 120);
            if (s32 == 1)
                printf("%d \n", s31);
            else
                printf("%d/%d \n", s31, s32);
        }
    }
    return 0;
}

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值