寒假集训2 c 时钟问题 hdu 5387

原文链接


Problem C

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other)
Total Submission(s) : 1   Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →

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

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



解释:主要分析出秒针,分针,时针度数之间的关系,由于最后需要输出分数形式,所以需要用到GCD

s的度数:s/60 * 360;

m的度数:m * 60 + s;

h的度数:(h%12 *  30)  + (m*60  + s) / 360 * 30;

关于分数的处理,只要把所有的分子化成3600即可;



<span style="font-size:14px;">#include <iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
using namespace std;


int gcd(int a, int b)
{
    if (b > a)
    {
        return gcd(b, a);
    }
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd(b, a % b);
    }
}

void  fun(int a, int b)
{
        int c = 180 * 3600;
        int max1 = max(a, b);
        int min1 = min(a, b);
        int res = max1 - min1;
        if (res > c)
        {
            res = 360 * 3600 - res;
        }
        int tem = gcd(res, 3600);
        int tem1 = 3600 / tem;
        if (tem1 != 1)
        {
            printf("%d/%d ", res/tem, tem1);
        }
        else
        {
            printf("%d ", res/tem);
        }

}

int main()
{
    //freopen("E:\input.txt", "r", stdin);
    int t;
    scanf("%d", &t);
    int h, m, s;
    int ns, nm, nh;
    while (t--)
    {
        scanf("%d:%d:%d", &h, &m, &s);
        //printf("%d %d %d\n", h, m, s);
        ns = s * 60 * 360;
        nm = (m * 60 + s)* 360;
        nh = (h % 12 * 30) * 3600 + (m * 60 + s) * 30;
        fun(nh, nm);
        fun(nh, ns);
        fun(nm, ns);
        printf("\n");
    }

    return 0;
}
 </span>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值