关闭

HDU 1209 ( Clock )

标签: 360c
935人阅读 评论(0) 收藏 举报
分类:
Problem : 1209 ( Clock )     Judge Status : Accepted
RunId : 5607237    Language : C++    Author : ssun
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta

#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

struct Time {
    int hour;
    int minu;
    double diff;
};

bool cmp(Time &t1,Time &t2)
{    
    if(t1.diff<t2.diff)
        return true;
    if(t1.diff>t2.diff)
        return false;
    if(t1.diff==t2.diff)
    {
        return t1.hour>t2.hour? false : true;
    }
}

int main()
{
    Time times[8];
    long t,i;
    char ch;

    while(cin>>t)
    {
        while(t--)
        {        
            for(i=0; i<5; i++)
            {
                cin>>times[i].hour>>ch>>times[i].minu;
            //    cout<<times[i].hour<<":"<<times[i].minu<<endl;
                if(times[i].hour>12)
                    times[i].diff = fabs(30*(times[i].hour-12)+times[i].minu/2.0-6*times[i].minu);
                else 
                    times[i].diff = fabs(30*times[i].hour+times[i].minu/2.0-6*times[i].minu);
                if(times[i].diff>180) times[i].diff = 360 -times[i].diff;
            }
            sort(times,times+5,cmp);
            printf("%02d:%02d\n",times[2].hour,times[2].minu);
        }
    }
    return 0;
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:117352次
    • 积分:1850
    • 等级:
    • 排名:千里之外
    • 原创:60篇
    • 转载:12篇
    • 译文:0篇
    • 评论:125条
    最新评论