hdu 5387 Clock

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

0hh<24 , 0mm<60 , 0ss<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
每行输出数据末尾均应带有空格
每秒钟,分针走是0.1°,时针走(1/120)°;每分钟,时针走0.5°。所以对于时针的角度来说总共走动了h*30+m*0.5+s/120,对于分针的角度来说总共走掉了m*6+s*0.1,对于秒针来说,总共走动了s*6.因为乘法比较除法来说时间复杂度更精确一点,所以我们把走的角度*120,变成全部都是整数,最后再除掉120即可。注意角度差大于180°的情况。


分数gcd形式的写法


#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

void gcd(int a,int b)
{
    int aa=a;
    int bb=b;
    while(b!=0) {
        int r=b;
        b=a%b;
        a=r;
    }
    printf("%d/%d ",aa/a,bb/a);
}
int main()
{
    int t,h,m,s,a,b,c;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d:%d:%d",&h,&m,&s);
        h%=12;
        if(h==24)
          h=0;
        else if(h>12)
            h=h-12;
        h=h*3600+m*60+s;
        m=m*720+s*12;
        s*=720;
        a=abs(h-m);
        b=abs(h-s);
        c=abs(m-s);
        if(a>21600)
            a=43200-a;
        if(b>21600)
            b=43200-b;
        if(c>21600)
            c=43200-c;
        if(a%120)
            gcd(a,120);
        else
            printf("%d ",a/120);
        if(b%120)
            gcd(b,120);
        else
            printf("%d ",b/120);
        if(c%120)
            gcd(c,120);
        else
            printf("%d ",c/120);
        printf("\n");
    }
    return 0;
}




害羞

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值