UVA1529 Clock 题解
duminghao123 · · 题解
UVA1529 Clock 题解
题面翻译
给定一个12小时制的时钟,问在一定时段内有几次时针与分针重合,按题目给定标准输出。
思路
对于时针来说,
每分钟转动的度数如下:
对于分针来说,每小时转动一圈,即
在转动过程中,由于是顺时针旋转,时针会在一分钟之内顺时针旋转
当分针与时针重合时,
至此,我们只需求出时间差与两个时间之间的分钟数,模拟每分钟的
注意
-
- 输出格式应正确。
- 还需注意一点,原题中没描述,要在程序开头输出
Program 3 by team X,程序结尾输出End of program 3 by team X。代码
#include<bits/stdc++.h> using namespace std; int a[100005][6],i=1,ds; int main(){ cout<<"Program 3 by team X\n"; while(cin>>a[i][1]>>a[i][2]>>a[i][3]>>a[i][4]){ ds=0; int q1=a[i][1],q2=a[i][2],q3=a[i][3],q4=a[i][4]; while(q1!=q3||q2!=q4){ q2++;ds++; if(q2==60){ q2=0;q1++; } if(q1==13){ q1=1; } } double dll=30.0*a[i][1]-5.5*a[i][2]; if(dll<=0) dll+=360; for(int k=1;k<=ds;k++){ dll-=5.5; if(dll<=0){ dll+=360; a[i][5]++; } } i++; } cout<<"Initial time Final time Passes"<<endl; for(int k=1;k<i;k++){ cout<<" "; if(a[k][1]<10) cout<<0<<a[k][1]; else cout<<a[k][1]; cout<<":"; if(a[k][2]<10) cout<<0<<a[k][2]<<" "; else cout<<a[k][2]<<" "; if(a[k][3]<10) cout<<0<<a[k][3]; else cout<<a[k][3]; cout<<":"; if(a[k][4]<10) cout<<0<<a[k][4]<<" "; else cout<<a[k][4]<<" "; if(a[k][5]<10) cout<<" "<<a[k][5]; else cout<<a[k][5]; if(k<i) cout<<endl; } cout<<"End of program 3 by team X\n"; return 0; }