题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=5387
4 00:00:00 06:00:00 12:54:55 04:40:00
0 0 0 180 180 0 1391/24 1379/24 1/2 100 140 120Hint每行输出数据末尾均应带有空格
#include<stdio.h> #include<math.h> #define eps 1e-8 int com(double m) { if(fabs(m)<eps) return 0; if(m<0) return -1; return 1; } void print2(double k) { for(int i=1;i<=360;i++) { if(com((i*k)-int(i*k+0.5))==0){ if(i==1) printf("%d ",int(i*k)); else printf("%d/%d ",int(i*k+0.5),i); return; } } } void print(double x,double y) { double k; k=fabs(x-y); if(k>=180) k=360-k; print2(k); } int main() { int hour,t; double h,m,s,minn,sec; scanf("%d",&t); while(t--) { scanf("%d:%lf:%lf",&hour,&minn,&sec); h=hour%12*30+minn*0.5+sec/120; m=minn*6+sec*0.1; s=sec*6; print(h,m); print(h,s); print(m,s); printf("\n"); } }