Algorithm


Problem Name: 2 AD-HOC - beecrowd | 2462

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2462

Flight

 

By OBI - Olimpíada Brasileira de Informática 2014 BR Brazil

Timelimit: 1

João was browsing the internet, looking flight schedules of various airlines between different cities, and noticed that in some cases direct flights between two cities had different times depending on whether they were flight onward or return.

The only possible explanation was to flights connecting cities located in different time zones. João then came to the conclusion that it would be possible to determine the difference in time zones, based only on schedules provided by the airlines.

For example, a flight out of the Haquérnia at 10:00 am and arrives in Nerdínia 22:00 hours, while another flight out of Nerdínia at 10:00 am and arrives in Haquérnia to 18:00. What is the explanation? Note that both flights using the same aircraft on the same route, a round, another back. In reality, the flight lasts 10 hours and Nerdínia is in a zone +2 hours hours ahead of time zone Haquérnia (hence the Haquérnia time zone is -2 hours ahead of time zone Nerdínia).

João then noticed the time table of several airlines, but made a mistake. He forgot to write down dates of departure and arrival. For example, if the departure of the flight is at 18:00 and arrival is at 14:00, João can not tell if the arrival date is the following the departure in flight that lasts 20 hours, between cities in the same time zone, or if the arrival date is the same as starting with a flight time of one hour, the destination city is in time zone five hours behind the time zone of the city origin.

Your task is to help João to determine the flight time and the difference between the time zones of arrival and departure of each pair of flights with table, a round another back, even without knowing the dates of the flights.

 

Input

 

The entry consists of only one line, with four times separated by a space. These times involve flights between two cities, A and B are, respectively, pA, cB, pB and cA. The pA time indicates the departure time of a flight from A to B, local time of A. The time indicates the arrival time of the flight even in town B, local time of B. The time is the starting time flight back from B to A, local time B. cA time is the arrival time of the flight back, local time of A.

 

Output

 

The output consists of one line, informing the flight time in minutes and how many hours B is ahead of A, in terms of time zones. The two values must be separated by a blank space.

 

 

 

Input Sample Output Sample

10:00 22:00 10:00 18:00

600 2

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <cstdio>
#define MODULO 1440
int main() {
    int a, b, c, d, e, f, g, h;
    int p1, c1, p2, c2;
    scanf("%d %*c %d %d %*c %d %d %*c %d %d %*c %d", &a, &b, &c, &d, &e, &f, &g,
          &h);
    p1 = 60 * a + b;
    c1 = 60 * c + d;
    p2 = 60 * e + f;
    c2 = 60 * g + h;
    // printf("%d %d %d %d\n",p1,c1,p2,c2);
    for (int duracao = 0; duracao  < = 720; duracao++) {
        for (int delta = 12; delta >= -12; delta--) {
            int p1t = (p1 + 60 * delta + duracao + MODULO) % MODULO;
            int p2t = (p2 - 60 * delta + duracao + MODULO) % MODULO;
            // printf("Duracao %d Delta %d\n",duracao,delta);
            // printf("%d %d %d %d\n",p1t,c1,p2t,c2);
            if (p1t != c1) continue;
            if (p2t != c2) continue;
            printf("%d %d\n", duracao, delta);
            return 0;
        }
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
10:00 22:00 10:00 18:00

Output

x
+
cmd
600 2
Advertisements

Demonstration


Previous
#2461 Beecrowd Online Judge Solution 2461 Bluff Solution in C, C++, Java, Js and Python
Next
#2463 Beecrowd Online Judge Solution 2463 Corredor Solution in C, C++, Java, Js and Python