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
Notice that the answer must be not more 180 and not less than 0
Input
There are
T
test cases
for each case,one line include the time
, ,
for each case,one line include the time
, ,
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
题意:给你几组数据,分别给出时间时,分,秒,让你求出时针和分针,时针和秒针,分针和秒针之间的夹角
思路:钟表一共分六十个格,一格为6度
秒针走一格,即6度的时候,分针走了一格的1/60,即6*(1/60)=1/10度,时针走了一格的1/(60*12),即6*(1/(60*12))=1/120度
分针走一格,
即6度的时候,时针走了一格的1/12,即6*(1/12)=1/2度所以为了避免出现小数,把度数都扩大120倍,具体看代码
#include<stdio.h> #include<string.h> #include<math.h> int fun(int x,int y) { int t; if(x>y) { t=x; x=y; y=t; } while(y) { t=x%y; x=y; y=t; } return x; } int main() { int t,n,m,s; char a,b; int p1,p2,p3,k; scanf("%d",&t); while(t--) { scanf("%d%c%d%c%d",&n,&a,&m,&b,&s); n=n%12;//钟表为12小时制 n=n*3600+m*60+s; //度数都扩大120倍,不会出现小数 m=m*720+s*12; s=s*720; p1=int(fabs(n-m));//时针分针之间的夹角 p2=int(fabs(n-s));//时针秒针之间的夹角 p3=int(fabs(m-s));//分针秒针之间的夹角 //度数应都不大于平角 if(p1>180*120) p1=360*120-p1; if(p2>180*120) p2=360*120-p2; if(p3>180*120) p3=360*120-p3; if(p1%120==0) //能除尽 printf("%d ",p1/120); else { k=fun(p1,120);//k为最大公约数 printf("%d/%d ",p1/k,120/k); } if(p2%120==0) //能除尽 printf("%d ",p2/120); else { k=fun(p2,120);//k为最大公约数 printf("%d/%d ",p2/k,120/k); } if(p3%120==0) //能除尽 printf("%d ",p3/120); else { k=fun(p3,120);//k为最大公约数 printf("%d/%d ",p3/k,120/k); } printf("\n"); } return 0; }