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; }



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值