fjnu 1684 Clock
来源:互联网 发布:那个网站注册域名便宜 编辑:程序博客网 时间:2024/04/20 20:20
Description
You are given a standard 12-hour clock with analog display, an hour hand and a minute hand. How many times does the minute hand pass the hour hand in a given time interval?
Input
The input contains an indefinite number of lines; each line contains four numbers. The first pair of numbers represents an "initial time" the second pair represents a "final time." In each such number pair, the first number represents hours, second number represents minutes. The hours will be in the range 1..12, the minutes in the range 0..59. No initial time and no final time will be an instant at which the minute hand just passes the hour hand. (In particular, 12 00 will not occur as an initial or final time.) No initial time will be the same as the corresponding final time. Between each initial time and corresponding final time, the hour hand will have turned less than one full revolution (360 degrees). As the hour hand turns from its initial position to its final position, it may or may not sweep past the number 12 on the clock's dial. If it does, then either the initial time is an "A.M." time and the final time a "P.M." time, or vice versa. If it does not, then either both times (initial and final) are "A.M." or both are "P.M."
Output
Each line of input gives rise to one line of output, containing the initial and final times, and the number of times the minute hand passes the hour hand between the initial time and the final time. Observe all details of formatting, such as upper/lower case letters, punctuation, blank spaces, and the absence of blank lines. In each time display, the hours and minutes are displayed in fields of width 2, separated by a colon. The ten's digit (of hours or minutes) is displayed as a zero if it is zero.
Sample Input
12 50 1 2 3 8 3 20 2 45 11 011 0 3 20 1 2 12 50 3 20 3 8
Sample Output
Program 3 by team XInitial time Final time Passes 12:50 01:02 0 03:08 03:20 1 02:45 11:00 8 11:00 03:20 4 01:02 12:50 11 03:20 03:08 10End of program 3 by team X
Hint
Here is a formatting template shown between two lines of the above output:
Initial time Final time Passes
12345678901234567890123456789012 12:50 01:02 0
KEY:首先要明白,要使分针超过时针,必然要有重合的时刻,先算出这些时刻,然后就好办
Source:#include<iostream>using namespace std;struct node {int hour;int minute;};node f[25];node s,e;void GetList(){int i,j=0;for(i=0;i<=11;i++,j++){f[i].hour=i;f[i].minute=60.0/11*j;}for(j=1;i<=23;i++,j++){f[i].hour=i+1;f[i].minute=60.0/11*j;}}int timecompare(node x,node y){if(x.hour>y.hour) return 1;else{if(x.hour==y.hour){if(x.minute>y.minute) return 1;else return 0;}else return 0;}}int countpass(){int passed=0;if(timecompare(s,e)){e.hour+=12;}int spos,epos;int i;for(i=0;i<=24;i++){if(!timecompare(s,f[i])) break;}spos=i;for(i=0;i<=24;i++){if(!timecompare(e,f[i])) break;}epos=i-1;return epos-spos+1;}int main(){//freopen("fjnu_1684.in","r",stdin);GetList();cout<<"Program 3 by team X"<<endl;cout<<"Initial time Final time Passes"<<endl;while(cin>>s.hour>>s.minute>>e.hour>>e.minute){cout<<" ";if(s.hour<10) cout<<"0";cout<<s.hour<<":";if(s.minute<10) cout<<"0";cout<<s.minute;cout<<" ";if(e.hour<10) cout<<"0";cout<<e.hour<<":";if(e.minute<10) cout<<"0";cout<<e.minute;int pass=countpass();printf("%8d/n",pass);}cout<<"End of program 3 by team X"<<endl;return 0;}
- fjnu 1684 Clock
- FJNU
- clock
- clock
- clock
- Clock
- CLOCK
- clock
- Clock
- clock
- clock
- CLOCK
- clock
- Clock
- Clock
- clock
- Clock
- Clock
- JAVA基础学习-简单数据类型
- 哈佛图书馆自习室墙上的训言
- 不要一辈子靠技术生存
- java获取指定目录下所有文件
- yum错误
- fjnu 1684 Clock
- 货币战争沉思录
- S60 3.0上的程序安装后启动运行和程序开机自动运行
- Linux操作系统下安装Mplayer播放器方法
- 奋斗
- 如何成为一个游戏人工智能开发者
- 学习JSP与Tomcat之转向其他jsp
- python文件处理
- 命名管道的创建