UVa12136 - Schedule of a Married Man(排序)

来源:互联网 发布:c编程教学免费视频 编辑:程序博客网 时间:2024/05/29 15:40

Last year we set a problem on bachelor arithmetic whichmade some bachelors really unhappy. So to even things up, we are making aproblem on the tough schedule of a married man.

 

Our dashing hero Danny has recently got married and thathas created a lot of problems for him, at least that is what his friends think.So many broken promises, so many missed appointments and dinners. Err! Danny,now is losing tracks of even simplest of calculations, so you must help him todecide whether he can attend his meeting or not. Danny is busy with his wifefor a large portion of the day. This large portion is denoted by a startingtime and an ending time. Then Danny has an important meeting in a day, hemisses that if it overlaps or touches (For example, if Danny�s time span withhis wife finishes at 18:00 and the meeting starts at 18:00 then the twoschedules conflict and Danny misses the meeting) the time scheduled for hiswife. Given the time span Danny has allotted for his wife and the time span ofthe meeting you, will have to find whether Danny misses that meeting or not.

 

Input

First line of the input file contains an integer N(0<N<2001) which denotes how many sets of inputs are there. The input foreach set is given in two lines. The description for each set is given below:

 

First line of each set contains two strings separated by asingle space. These two strings denote the time span Danny is busy with hiswife. The second line also contains two strings which denotes the time whenDanny has to attend a meeting. All the strings that denote time are of theformat hh:mm (two digit for hour and two digit for minute). For example �fortyfive past eight� (Morning) is denoted as 08:45, �forty five past 9� (night) isdenoted as 21:45.� You can assume thatall times are valid 24-hour clock time, starting time strictly precedes endingtime and all times are within a single day.

 

Output

For each set of input produce one line of output. Thisline contains the serial of output followed by a string which denotes Danny�sdecision. If Danny can attend the meeting then print �Hits Meeting� and ifDanny misses (Mrs) the meeting as it conflicts with the time allotted for hiswife print �Mrs Meeting� instead.

 

Sample Input��������������������������� Output for SampleInput

3

17:47 22:40

06:18 17:04

10:44 17:05

01:11 01:27

03:36 19:02

14:33 15:24

 

Case 1: Hits Meeting

Case 2: Hits Meeting

Case 3: Mrs Meeting

 

题意:给出两个时间段,判断时间是否有冲突

思路:根据起始时间将两个赶时间段排序

#include <cstdio>#include <algorithm>using namespace std;const int MAXLINE = 100;struct Time{int start, end;bool operator < (const Time &other) const{if (start != other.start) return start < other.start;return end < other.end;}};char buf[MAXLINE];Time time[2];bool input(){    gets(buf);int hour1, min1, hour2, min2;sscanf(buf, "%d:%d %d:%d", &hour1, &min1, &hour2, &min2);time[0].start = hour1 * 60 + min1;time[0].end = hour2 * 60 + min2;gets(buf);sscanf(buf, "%d:%d %d:%d", &hour1, &min1, &hour2, &min2);time[1].start = hour1 * 60 + min1;time[1].end = hour2 * 60 + min2;sort(time, time + 2);    return true;}void solve(){    if (time[0].end < time[1].start) {printf("Hits Meeting\n");} else {printf("Mrs Meeting\n");}}int main() {#ifndef ONLINE_JUDGE    freopen("d:\\OJ\\uva_in.txt", "r", stdin);#endif       int cas;gets(buf);sscanf(buf, "%d", &cas);       for (int i = 1; i <= cas; i++) {        input(); printf("Case %d: ", i);        solve();    }    return 0;}



0 0
原创粉丝点击