多校-1008-Clock

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


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
每行输出数据末尾均应带有空格


题意是给你时间,然后让你去算时针和分针的夹角,时针和秒针的夹角,分针和秒针的夹角,小于180的角

 时针的夹角是 30*h +0.5*m + 0.5/60 *s;

  分针的夹角     60×m + 0.1*s;

  秒针的夹角       6*s;

   大于 13:00:00 和 1:00:00 相同

 

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
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);
        int ht, mt, st;
         if(h >= 12)
            h -=12;
        ht = 18000*h+300*m + 5*s;
        mt = 3600*m+60*s;
        st = 3600*s;

        int hm, hs, ms;
        if(ht > mt)
            hm = ht-mt;
        else
            hm = mt-ht;
        if(360*600-hm<hm)
        {
            if(360*600-hm>0)
             hm = 360*600-hm;
        }
        if(ht > st)
            hs = ht-st;
        else
            hs = st-ht;
        if(360*600-hs<hs)
        {
            if(360*600-hs > 0)
              hs = 360*600-hs;
        }
        if(mt > st)
            ms = mt - st;
        else
            ms = st - mt;
        if(360*600-ms<ms)
        {
            if(360*600-ms>0)
             ms = 360*600-ms;
        }
        if(hm%600==0)
        {
            printf("%d ",hm/600);
        }
        else
        {
            if(hm > 600)
                printf("%d/%d ",hm/gcd(hm,600),600/gcd(hm,600));
            else
                printf("%d/%d ",hm/gcd(600,hm),600/gcd(600,hm));
        }
        if(hs%600==0)
        {
            printf("%d ",hs/600);
        }
        else
        {
            if(hs > 600)
                printf("%d/%d ",hs/gcd(hs,600),600/gcd(hs,600));
            else
                printf("%d/%d ",hs/gcd(600,hs),600/gcd(600,hs));
        }
        if(ms%600==0)
        {
            printf("%d ",ms/600);
        }
        else
        {
            if(ms > 600)
                printf("%d/%d ",ms/gcd(ms,600),600/gcd(ms,600));
            else
                printf("%d/%d ",ms/gcd(600,ms),600/gcd(600,ms));
        }
        printf("\n");
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值