1156: 钟

来源:互联网 发布:淘宝买到假货怎么投诉 编辑:程序博客网 时间:2024/05/16 23:43

Description

对于时钟,我们再熟悉不过了,有时针、分针、秒针三根针,用他们的位置表示当前的时间。 问题是这样的,Faith有一个电子手表,上面显示的时间格式为 hh:mm。Faith想知道手表显示的这个时间在钟上的时针和分针的夹角有多大。

Input

题目有多组输入,请处理到文件结束。 每组数据一行,格式如 hh:mm(如 11:08)

Output

输出当前时间以及相应时间时针与分针的夹角(保留到小数点后一位),以一个空格隔开。

Sample Input

00:00
06:00

Sample Output

00:00 0.00

6:00 180.0


数学题。设小时为a       分钟为b

输入的小时数就是时针走过的数字

即可以求出当分针走到整12位数时,时针所走角度为 a * (360 / 12)  (360度里面,每走一个数字时针就走过 360 / 12 度....

当分针走动时,一小时即时针走了30度,又因为分针走的时间代表分钟数,而一小时有60分,即时针随着分针走过的角度为 b * (30 / 60)  

因而,时针所走总角度 x = a * (360 / 12 ) + b * (30 / 60)

 

分针走的角度y

因为一分钟走过6度,所以 y = b * 6 ;


最后计算出角度做比较。。


注:printf的输出。

(1)printf("%0xd",);此法输出可以用0将数字前x位补全。

(2)printf("%.xlf"); 输出为数字小数点后x位数


#include<cstdio>#include<cstring>#include<iostream>#include<utility>#include<string>#include<vector>#include<algorithm>#include<queue>#include<cstdlib>#include<cmath>#include<stack>using namespace std;int main(){#ifndef ONLINE_JUDGEfreopen("1.txt","r",stdin);#endifint a,b;while(~scanf("%d:%d",&a,&b)){double x = (a % 12) * 30 + b * 0.5 ;double y = b * 6 ;double n = fabs(x - y) ;printf("%02d:%02d ",a,b);if(n <= 180)printf("%.1lf\n",n);elseprintf("%.1lf\n",360 - n);}return 0;}

0 0
原创粉丝点击