HDU 5387 Clock(计算时针与分针 时针与秒针 分针与秒针的夹角)

本文介绍了一道关于计算时钟中时针、分针及秒针之间角度的问题。通过具体的样例输入输出展示了如何计算任意两针之间的夹角,并确保角度范围在0到180度之间。使用了简单的数学和编程技巧来解决这个问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Clock

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


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

Source




求得夹角必须都是小于180度的








#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<stack>
#include<map>

using namespace std;

int x,y,z;

int gcd(int x, int y)
{
    if (x%y) return gcd(y, x%y);
    return y;
}


int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d:%d:%d",&x,&y,&z);
        int zz = z*6*120;
        int yy = (y*60+z)*12;///角度*10
        int xx = ((x%12)*3600 + y*60 + z);///角度*120
        int xy = abs(xx - yy);
        int xz = abs(xx - zz);
        int yz = abs(yy - zz);
        if(xy>120*180)
        {
            xy = 360*120 - xy;
        }
        if(xz > 120*180)
        {
            xz = 360*120 - xz;
        }
        if(yz > 120 * 180)
        {
            yz = 360*120 - yz;
        }
        if(xy%120 == 0)
        {
            printf("%d ",xy/120);
        }
        else
        {
            int pp = gcd(xy,120);
            printf("%d/%d ",xy/pp,120/pp);
        }
        if(xz%120 == 0)
        {
            printf("%d ",xz/120);
        }
        else
        {
            int pp = gcd(xz,120);
            printf("%d/%d ",xz/pp,120/pp);
        }
        if(yz%120 == 0)
        {

            printf("%d ",yz/120);
        }
        else
        {
            int pp = gcd(yz,120);
            printf("%d/%d ",yz/pp,120/pp);
        }
        printf("\n");


    }
    return 0;
}


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶孤心丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值