HDU 5387 Clock(模拟)

70 篇文章 0 订阅

Clock

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1209    Accepted Submission(s): 685


Problem Description
Give a time.(hh:mm:ss),you should answer the angle between any two of the minute.hour.second hand
Notice that the answer must be not more 180 and not less than 0
 

Input
There are T (1T104) test cases
for each case,one line include the time

0hh<24 , 0mm<60 , 0ss<60
 

Output
for each case,output there real number like A/B.(A and B are coprime).if it's an integer then just print it.describe the angle between hour and minute,hour and second hand,minute and second hand.
 

Sample Input
  
  
4 00:00:00 06:00:00 12:54:55 04:40:00
 

Sample Output
  
  
0 0 0 180 180 0 1391/24 1379/24 1/2 100 140 120
Hint
每行输出数据末尾均应带有空格
 

Author
SXYZ
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5994  5993  5992  5991  5990 

题意:给定一个时间,求出时针分针秒针两两夹角。
思路:选拔赛的时候做的一道题,当时没多少时间于是决定放弃这道题,结果今天搞了搞发现好简单,连对分数的处理也好简单,简直无语凝噎。思路就是先求 对角度,即时针距离0点的角度,分针距离0点的角度,秒针距离0点的角度,然后两两相减。分数的处理就是直接把减完的式子转化为分数形式,然后上下约分,如果分母是1直接输出分子,还有就是要求输出锐角,所以分子需要判断与360*120-分子的大小,如果大于就转化为360*120-分子。

#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;

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

int main(){
	
	int t;
	scanf("%d",&t);
	while(t--){
		int h,m,s;
		scanf("%d:%d:%d",&h,&m,&s);
		int hhp,lhp,hmp,lmp,hsp,lsp;
		hhp=abs(h%12*3600-660*m-11*s);
		int sum=360*120-hhp;
		if(hhp>sum)
			hhp=sum;
		lhp=120;
		int k=gcd(hhp,lhp);
		hhp=hhp/k;
		lhp=lhp/k;
		if(lhp==1)
			printf("%d ",hhp);
		else
			printf("%d/%d ",hhp,lhp);
		hmp=abs(h%12*3600+60*m-719*s);
		lmp=120;
		sum=360*120-hmp;
		if(hmp>sum)
			hmp=sum;
		k=gcd(hmp,lmp);
		hmp/=k;
		lmp/=k;
		if(lmp==1)
			printf("%d ",hmp);
		else
			printf("%d/%d ",hmp,lmp);
		hsp=abs(720*m-708*s);
		lsp=120;
		sum=360*120-hsp;
		if(hsp>sum)
			hsp=sum;
		k=gcd(hsp,lsp);
		hsp/=k;
		lsp/=k;
		if(lsp==1)
			printf("%d \n",hsp);
		else
			printf("%d/%d \n",hsp,lsp);
	}
	return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值