2018 Blue Bridge Cup Provincial Competition C/C++ Group A Topic 6 Flight Time


Title: Flight Time

 

[Problem background]
Little h went to the United States to participate in the Blue Bridge Cup International Competition. Xiao H's girlfriend found out that Xiao H departed at ten o'clock in the morning and arrived in the United States at twelve o'clock in the morning, so she sighed, "Now the plane is flying so fast, you can reach the United States in two hours."

 

Little h is terrified of flying at supersonic speeds. After careful observation, it was found that the takeoff and landing times of the planes were all local time. Since there is a 12-hour time difference between Beijing and the eastern part of the United States, the plane needs a total of 14 hours of flight time.

 

Soon after, Xiao H's girlfriend went to the Middle East for an exchange. Little h doesn't know the time difference between the Middle East and Beijing. But Xiao H got the take-off and landing time of his girlfriend's round-trip flight. Little h wants to know the flight time of his girlfriend's flight.

 

[Problem description]
For a flight that may cross time zones, the takeoff and landing time of the round trip is given. Assuming that the round-trip flight time of the plane is the same, find the flight time of the plane.

 

【Input format】
Read data from standard input.
An input contains multiple sets of data.

 

The first line of input is a positive integer T, indicating the number of input data sets.
Each set of data contains two rows, the first row is the takeoff and landing time of the outbound trip, and the second row is the takeoff and landing time of the return trip.
The format of take-off and landing time is as follows

 

h1:m1:s1 h2:m2:s2
or
h1:m1:s1 h3:m3:s3 (+1)
or
h1:m1:s1 h4:m4:s4 (+2)
means the flight is at h1 hour m1 minute local time s1 seconds to take off,

 

The first format indicates landing at h2 hours m2 minutes s2 seconds of local time on the current day.
The second format indicates landing at h3 hours m3 minutes s3 seconds of local time the next day.
The third format indicates landing at h4:m4:s4:3 hours local time on the third day.

 

For all times given in the form of h:m:s in this problem, it is guaranteed ( 0<=h<=23, 0<=m,s<=59 ).

 

【Output Format】
Output to standard output.

 

For each set of data, output a line of time hh:mm:ss, indicating that the flight time is hh hours mm minutes ss seconds.
Note that when the time is a single digit, leading zeros must be filled. For example, three hours, four minutes and five seconds should be written as 03:04:05.

 

[Sample input]
3
17:48:19 21:57:24
11:05:18 15:14:23
17:21:07 00:31:46 (+1)
23:02:41 16:13:20 (+1)
10:19:19 20:41:24
22:19:04 16:41:09 (+1)

 

[Sample output]
04:09:05
12:10:39
14:22:05

 

[Restrictions and Agreements]
Ensure that the input time is legal, and the flight time does not exceed 24 hours.

 


Resource agreement:
peak memory consumption (including virtual machines) < 256M
CPU consumption < 1000ms

 


Please output strictly according to the requirements, and don't superfluously print redundant content similar to: "Please enter...".

 

Note:
The main function needs to return 0;
only use the ANSI C/ANSI C++ standard;
do not call special functions that depend on the compilation environment or operating system.
All dependent functions must be clearly #include <xxx> in the source file
and common header files cannot be omitted through project settings.

When submitting the program, pay attention to select the desired language type and compiler type.

Idea: The question is not difficult. In my opinion, there is mainly a problem of designing strings. First, replace all the given time with seconds. We can solve it through a proposed equation: suppose t is the time difference, and time is the flight time , that is, statt1 + time + t = end1, statt2 + time - t = end2; in this way, the time zone difference can be ignored directly, and the code is directly added:

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <ctype.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#define maxn 10005
using namespace std;
const int day = 24*60*60;
const int hour = 60*60;
const int mintes = 60;

int input1()
{
    int a,b,c;
    scanf("%d:%d:%d",&a,&b,&c);
    int time = a*hour + b*mintes + c;
    return time;
}

int input2()
{
    int a,b,c;
    scanf("%d:%d:%d",&a,&b,&c);
    int time = a*hour + b*mintes + c;
    char ch,cn;
    while( (ch = getchar())!='\n' && ch != '\r' )
    {
        if(ch == '(')
        {
            getchar();  //用来把+号吸收掉 
            cn = getchar(); //用来接收天数 
            time = time + (cn - '0')*day;
        }
    } 
    return time;
}

void print(int time)
{
    int a,b,c;
    a = time/hour;
    time = time % hour;
    b = time / mintes;
    time = time % mintes;
    c = time;
    printf("%02d:%02d:%02d\n",a,b,c);
}

int main()
{
    int h1,m1,s1,h2,m2,s2;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int start1 = input1();
        int end1 = input2();
        int start2 = input1();
        int end2 = input2();
        int ans = 0;
        ans = (end1 - start1) + (end2 - start2);
        print(ans/2);
    }
    
	return 0;
}

 

Guess you like

Origin blog.csdn.net/xiaoning9299/article/details/88560290