hdu 5387 Clock

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  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 

        
  
题意:给你几组数据,分别给出时间时,分,秒,让你求出时针和分针,时针和秒针,分针和秒针之间的夹角
思路:钟表一共分六十个格,一格为6度
      秒针走一格,即6度的时候,分针走了一格的1/60,即6*(1/60)=1/10度,时针走了一格的1/(60*12),即6*(
1/(60*12))=1/120度
           分针走一格,
即6度的时候,时针走了一格的1/12,即6*(1/12)=1/2度
所以为了避免出现小数,把度数都扩大120倍,具体看代码

#include<stdio.h>
#include<string.h>
#include<math.h>
int fun(int x,int y)
{
    int t;
    if(x>y)
    {
        t=x;
        x=y;
        y=t;
    }
    while(y)
    {
        t=x%y;
        x=y;
        y=t;
    }
    return x;
}
int main()
{
    int t,n,m,s;
    char a,b;
    int p1,p2,p3,k;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%c%d%c%d",&n,&a,&m,&b,&s);
        n=n%12;//钟表为12小时制
        n=n*3600+m*60+s; //度数都扩大120倍,不会出现小数
        m=m*720+s*12;
        s=s*720;
        p1=int(fabs(n-m));//时针分针之间的夹角
        p2=int(fabs(n-s));//时针秒针之间的夹角
        p3=int(fabs(m-s));//分针秒针之间的夹角
        //度数应都不大于平角
        if(p1>180*120)
            p1=360*120-p1;
        if(p2>180*120)
            p2=360*120-p2;
        if(p3>180*120)
            p3=360*120-p3;
        if(p1%120==0)  //能除尽
            printf("%d ",p1/120);
        else
        {
            k=fun(p1,120);//k为最大公约数
            printf("%d/%d ",p1/k,120/k);

        }
        if(p2%120==0)  //能除尽
            printf("%d ",p2/120);
        else
        {
            k=fun(p2,120);//k为最大公约数
            printf("%d/%d ",p2/k,120/k);

        }
        if(p3%120==0)  //能除尽
            printf("%d ",p3/120);
        else
        {
            k=fun(p3,120);//k为最大公约数
            printf("%d/%d ",p3/k,120/k);

        }
        printf("\n");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值