多校联合第八场hdu5387Clock 最大公约数

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


做多校的题都20道了,头一次自己过了一个,太激动了!!即使是水到不行,AC率过半 WA了几次 都错哪里了呢?

1.貌似fabs取绝对值的那个函数还是自己写比较好 C++就CE了

2.改程序的时候想起来了超过180度用360减 但是为什么没注意到超过12点得减去12呢 想到减去12了 为什么脑袋短路写成>12呢 →_→

#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int gcd(int a,int b)
{
    int r=a%b;
    while(r)
    {
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int fun(int x)
{
    if(x>0) return x;
    return -x;
}
int t,hh,mm,ss,tmp,a,b,c;
int main()
{
   // freopen("cin.txt","r",stdin);

    char ch;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%c%d%c%d",&hh,&ch,&mm,&ch,&ss);
        if(hh>=12) hh-=12;
       // printf("%d %d %d\n",hh,mm,ss);
       a=fun(hh*3600-mm*660-ss*11);
       if(a>21600) a=43200-a;
       tmp=gcd(a,120);
       if(tmp!=120)
            printf("%d/%d ",a/tmp,120/tmp);
       else if(tmp==120)
            printf("%d ",a/tmp);
       b=fun(hh*3600+mm*60-ss*719);
       if(b>21600) b=43200-b;
       tmp=gcd(b,120);
       if(tmp!=120)
            printf("%d/%d ",b/tmp,120/tmp);
       else if(tmp==120)
            printf("%d ",b/tmp);
       c=fun(mm*60-ss*59);
       if(c>1800) c=3600-c;
       tmp=gcd(c,10);
     //  cout<<tmp<<endl;
       if(tmp!=10)
            printf("%d/%d \n",c/tmp,10/tmp);
       else if(tmp==10)
            printf("%d \n",c/10);
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值