码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5387 Clock

时间:2015-08-13 18:01:28      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:

代码:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int f(int a)
{
    return a>0?a:(-a);
}

int gcd(int a,int b)
{
    return b>0?gcd(b,a%b):a;
}

int main()
{
    int t;
    int hh,mm,ss;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d:%d:%d",&hh,&mm,&ss);
        int s_deg,m_deg,h_deg;
        s_deg=ss*6*3600;
        m_deg=mm*6*3600+6*ss*60;
        h_deg=hh*30;
        while(h_deg>=360)
        {
            h_deg-=(360);
        }
        h_deg=h_deg*3600+mm*30*60+ss*30;
        if(f(h_deg-m_deg)/3600.0<=180.0)
        {
            int x=f(h_deg-m_deg);
            int xx=gcd(x,3600);
            if(xx!=3600)
            printf("%d/%d ",x/xx,3600/xx);
            else
              printf("%d ",x/xx);
        }
        else
        {
            int x=360*3600-f(h_deg-m_deg);
            int xx=gcd(x,3600);
            if(xx!=3600)
            printf("%d/%d ",x/xx,3600/xx);
            else
              printf("%d ",x/xx);
        }
        if(f(h_deg-s_deg)/3600.0<=180.0)
        {
            int x=f(h_deg-s_deg);
            int xx=gcd(x,3600);
           if(xx!=3600)
            printf("%d/%d ",x/xx,3600/xx);
            else
              printf("%d ",x/xx);
        }
        else
        {
            int x=360*3600-f(h_deg-s_deg);
            int xx=gcd(x,3600);
           if(xx!=3600)
            printf("%d/%d ",x/xx,3600/xx);
            else
              printf("%d ",x/xx);
        }
        if(f(m_deg-s_deg)/3600.0<=180.0)
        {
            int x=f(m_deg-s_deg);
            int xx=gcd(x,3600);
           if(xx!=3600)
            printf("%d/%d ",x/xx,3600/xx);
            else
              printf("%d ",x/xx);
        }
        else
        {
            int x=360*3600-f(m_deg-s_deg);
            int xx=gcd(x,3600);
            if(xx!=3600)
            printf("%d/%d ",x/xx,3600/xx);
            else
              printf("%d ",x/xx);
        }
        printf("\n");
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

hdu 5387 Clock

标签:

原文地址:http://blog.csdn.net/xky1306102chenhong/article/details/47615759

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!