HDU 5387 Clock (MUT#8 模拟)

【题目链接】:click here~~

【题目大意】给定一个时间点,,求时针和分针夹角,时针和秒针夹角,分针和秒针夹角

模拟题,注意细节

代码:

#include<bits/stdc++.h>using namespace std;inline int read(){int c=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){c=c*10+ch-'0';ch=getchar();}return c*f;}int gcd(int a,int b){return b==0?a:gcd(b,a%b);}int main(){ int t,h,m,s; t=read(); while(t–){scanf("%d:%d:%d",&h,&m,&s);h%=12;m%=60;s%=60;int ss=s*720; //秒针走过的角度int mm=720*m+12*s; //分针走过的角度int hh=3600*h+60*m+s; //时针走过的角度//计算角度之差int hm=abs(hh-mm);int hs=abs(hh-ss);int ms=abs(mm-ss);//判断hm=min(hm,120*360-hm);hs=min(hs,120*360-hs);ms=min(ms,120*360-ms);//取最大公约数int ghm=gcd(hm,120);int ghs=gcd(hs,120);int gms=gcd(ms,120);if(ghm==120) cout<<hm/120;else cout<<hm/ghm<<"/"<<120/ghm;if(ghs==120) cout<<" "<<hs/120<<" ";else cout<<" "<<hs/ghs<<"/"<<120/ghs<<" ";if(gms==120) cout<<ms/120<<" "<<endl;else cout<<ms/gms<<"/"<<120/gms<<" "<<endl; } return 0;}

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

即使是不成熟的尝试,也胜于胎死腹中的策略。

HDU 5387 Clock (MUT#8 模拟)

相关文章:

你感兴趣的文章:

标签云: