zoukankan      html  css  js  c++  java
  • HDU1209:Clock

    参考:https://blog.csdn.net/libin56842/article/details/8990530

    https://blog.csdn.net/u011479875/article/details/47194363

    https://blog.csdn.net/u012712087/article/details/48008745

    https://www.cnblogs.com/AndyJee/archive/2014/07/02/3821067.html

     1 #include <iostream>
     2 #include <cmath>
     3 #include <algorithm>
     4 #include <cstdio>
     5 #include <cstring>
     6 #include <cctype>
     7 #include <sstream>
     8 using namespace std;
     9 int t;
    10 int nu[15]; 
    11 struct node
    12 {
    13     int h,m;
    14     float v;
    15 }no[15];
    16 float findv(int x,int y)//求夹角 
    17 {
    18     x=x%12;//要先取余~ 
    19     y=y;//分针不用取余~ 
    20     float vx=x*30+y*0.5,vy=y*6,vxy=fabs(vx-vy);//vx为时针角,vy为分针角,把30等数字写成30.0形式能缩短时间!
    21     if (vxy<=180)
    22     {
    23         return vxy;
    24     }
    25     else
    26     {
    27         return 360-vxy;
    28     }
    29 }
    30 bool cmp(struct node x,struct node y)
    31 {
    32     if (x.v<y.v)//不是<=~ 
    33     {
    34         return true;
    35     }
    36     else if(x.v==y.v&&x.h<y.h)
    37     {
    38         return true;
    39     }
    40     else
    41     {
    42         return false;
    43     }
    44 }
    45 int main()
    46 {
    47 //    freopen("text.txt","r",stdin);
    48     while (scanf("%d",&t)!=EOF)
    49     {
    50         string s;
    51         getchar();//用getline前要清除回车~ 
    52         for (int i=0;i<t;i++)
    53         {
    54             getline(cin,s,'
    ');//不能用cin,cin遇空格会结束~ 
    55             for (int j=0;j<s.length();j++)
    56             {
    57                 if (!isalnum(s[j]))
    58                 {
    59                     s[j]=' ';
    60                 }
    61             }
    62             stringstream ss(s);
    63             int c=0;
    64             memset(nu,0,sizeof(nu));//数组等容器设为全局变量方便写测试函数! 
    65             while (ss>>nu[c])
    66             {
    67                 c++;
    68             }
    69             int j=0;
    70             memset(no,0,sizeof(no));
    71             for (int i=1;i<c;i+=2)
    72             {
    73                 int hh=no[j].h=nu[i-1];
    74                 int mm=no[j].m=nu[i];
    75                 no[j].v=findv(hh,mm);
    76                 j++;
    77             }
    78             sort(no,no+5,cmp);//范围是no+5不是no+c~ 
    79 //            for (int k=0;k<5;k++)//提交前要记得注释掉测试语句~ 
    80 //            {
    81 //                printf("%d %d %f
    ",no[k].h,no[k].m,no[k].v);
    82 //            }
    83             printf("%02d:%02d
    ",no[2].h,no[2].m);
    84         }
    85     }
    86     
    87     return 0;
    88 } 
  • 相关阅读:
    volatile关键字
    const关键字祥解
    extern关键字祥解
    gcc和g++使用澄清
    [APIO2014]连珠线
    点名
    四轮车
    盘子序列
    序列问题
    长途旅行
  • 原文地址:https://www.cnblogs.com/hemeiwolong/p/9391016.html
Copyright © 2011-2022 走看看