多校联合第八场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;
}

 

你可能感兴趣的:(多校联合第八场hdu5387Clock 最大公约数)