杭电OJ 题 1209 Clock 解题报告
来源:互联网 发布:php上传任意文件 编辑:程序博客网 时间:2024/06/10 01:21
Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2985 Accepted Submission(s): 914
Total Submission(s): 2985 Accepted Submission(s): 914
Problem Description
There is an analog clock with two hands: an hour hand and a minute hand. The two hands form an angle. The angle is measured as the smallest angle between the two hands. The angle between the two hands has a measure that is greater than or equal to 0 and less than or equal to 180 degrees.
Given a sequence of five distinct times written in the format hh : mm , where hh are two digits representing full hours (00 <= hh <= 23) and mm are two digits representing minutes (00 <= mm <= 59) , you are to write a program that finds the median, that is, the third element of the sorted sequence of times in a nondecreasing order of their associated angles. Ties are broken in such a way that an earlier time precedes a later time.
For example, suppose you are given a sequence (06:05, 07:10, 03:00, 21:00, 12:55) of times. Because the sorted sequence is (12:55, 03:00, 21:00, 06:05, 07:10), you are to report 21:00.
Given a sequence of five distinct times written in the format hh : mm , where hh are two digits representing full hours (00 <= hh <= 23) and mm are two digits representing minutes (00 <= mm <= 59) , you are to write a program that finds the median, that is, the third element of the sorted sequence of times in a nondecreasing order of their associated angles. Ties are broken in such a way that an earlier time precedes a later time.
For example, suppose you are given a sequence (06:05, 07:10, 03:00, 21:00, 12:55) of times. Because the sorted sequence is (12:55, 03:00, 21:00, 06:05, 07:10), you are to report 21:00.
Input
The input consists of T test cases. The number of test cases (T) is given on the first line of the input file. Each test case is given on a single line, which contains a sequence of five distinct times, where times are given in the format hh : mm and are separated by a single space.
Output
Print exactly one line for each test case. The line is to contain the median in the format hh : mm of the times given. The following shows sample input and output for three test cases.
Sample Input
300:00 01:00 02:00 03:00 04:0006:05 07:10 03:00 21:00 12:5511:05 12:05 13:05 14:05 15:05
Sample Output
02:0021:0014:05
——————————————————————————————————————————————————————————————————
注意时间的计算方法,时针是跟着分针动的,比如7:30的角度不是7点的角度和30分的角度只差,小时角度的计算还要加上分针的偏移量
还有当角度相同时,时间小的在前面
/************************ 程序名:clock.cpp* 功能:ACM************************/#include <stdio.h>#include <string.h>void PubbleSort(double (*)[3], int);int main(){ int T; char time[5][5], string[30], c; double sequence[5][3]; int i, j, t; double hour, min, degree; scanf("%d", &T); c=getchar(); while(T--) { gets(string); t = 0; for(i = 0; i < 5; i++) { for(j = 0; j < 5; j++) { time[i][j] = string[t++]; } t++; } for(i = 0; i < 5; i++) { hour = (time[i][0]-'0')*10+time[i][1]-'0'; min = (time[i][3]-'0')*10+time[i][4]-'0'; sequence[i][2] = hour; if(hour > 12) { hour -= 12; } if((hour+min/60.0)*30 > min*6) { degree = (hour+min/60.0)*30-min*6; } else { degree = min*6-(hour+min/60.0)*30; } if(degree > 180) { degree = 360 - degree; } sequence[i][0] = degree; sequence[i][1] = i; } PubbleSort(sequence, 5); i = sequence[2][1]; for(j = 0; j < 5; j++) { printf("%c", time[i][j]); } printf("\n"); } return 0;}void PubbleSort(double (*array)[3], int n){ int i, j; double temp_1, temp_2, temp_3; for(i = 0; i < n-1; i++) { for(j = 0; j < n-i-1; j++) { if(array[j][0] >= array[j+1][0]) { if(array[j][0] == array[j+1][0]) { if(array[j][2] > array[j+1][2]) { temp_1 = array[j][0]; temp_2 = array[j][1]; temp_3 = array[j][2]; array[j][0] = array[j+1][0]; array[j][1] = array[j+1][1]; array[j][2] = array[j+1][2]; array[j+1][0] = temp_1; array[j+1][1] = temp_2; array[j+1][2] = temp_3; } } else { temp_1 = array[j][0]; temp_2 = array[j][1]; temp_3 = array[j][2]; array[j][0] = array[j+1][0]; array[j][1] = array[j+1][1]; array[j][2] = array[j+1][2]; array[j+1][0] = temp_1; array[j+1][1] = temp_2; array[j+1][2] = temp_3; } } } } /*for(i = 0; i < 5; i++) { printf("degree=%.0lf hour=%.0lf ", array[i][0], array[i][2]); } printf("\n");*/}
- 杭电OJ 1209题clock 解题报告
- 杭电OJ 题 1209 Clock 解题报告
- 杭电OJ题 1393 Weird Clock解题报告
- 杭电OJ题 1106 排序 解题报告
- 杭电OJ题 1236 排名 解题报告
- 杭电OJ题 1391 Number Steps 解题报告
- 杭电OJ题 1347 Grandpa is Famous解题报告
- 杭电OJ题 1361 Parencodings解题报告
- 杭电OJ题 1379 DNA Sorting解题报告
- 杭电OJ题 1390 Binary Numbers解题报告
- 杭电OJ题 Goldbach's Conjecture解题报告
- 杭电OJ题 1408 盐水的故事 解题报告
- 杭电OJ题 1412 {A} + {B} 解题报告
- 杭电OJ题 1444 Maya Calendar解题报告
- 杭电OJ题 1491 Octorber 21st 解题报告
- 杭电OJ题 1555 How many days?解题报告
- 杭电OJ题 1562 Guess the number解题报告
- 杭电OJ题 1587 Flowers解题报告
- 用栈逆置一个线性表
- 多科成绩单
- 心中的顽石
- C++ Primer 9.40习题 计算sentence有多少个单词,并输出最长、最短的单词d
- 人生絮语
- 杭电OJ 题 1209 Clock 解题报告
- 行为识别特征提取综述
- 轮询注册表
- 树操作
- linuxmint mysql使用
- excel常用函数大全(二)
- poj 2560最小生成树 prim
- 标签的target属性
- Sharepoint 2010 for windows server 2008 r2 x64安装