Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1536

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

Libertadores

 

By Fabiola de Souza, UFU BR Brazil

Timelimit: 1

The Libertadores Cup is the main soccer competition among professional clubs of South America, organized by the South American Confederation of Soccer (CONMEBOL). This cup is known for having a very complicated regulation, especially for the quarter finals and semi-final.

These stages are played roundtrip matches in the playoff system. Wins the team that makes the highest score accumulated in the two matches, with 3 points for a win and 1 point in case of a tie, both per match. In case of a tie in score, the tiebreaker criteria are:

1) goal difference (number of goals for minus the number of goals against)

2) most goals scored in the away match and

3) penalty shootout

All criteria must be applied considering the accumulated of the two matches.

Can you develop an algorithm that, given the results of the roundtrip matches, it identifies the winning team?

 

Input

 

The first line of input gives the number of test cases N (1 ≤ N ≤ 100). Each test case consists of two scores: the outcome of match 1 and the outcome of the 2. The score is represented by the format M x V, where M (1 ≤ M ≤ 100) is the number of goals for principal team and V (1 ≤ V ≤ 100) is the number of goals for the visiting team. As for each test case there are 2 matches, consider that Team 1 is always the principal of the first match and the visitor of the second and vice versa for Team 2.

 

Output

 

For each test case, print a line containing "Time 1" (without quotes) if Team 1 is the winner of the playoff, " Time 2" (without quotes) if the Team 2 is the winner of the playoff and "Penaltis" (without quotes) if you can not identify the winner in conventional time.

 

 

 

Sample Input Sample Output

4

1 x 1

2 x 1

2 x 0

2 x 1

1 x 1

2 x 2

3 x 1

3 x 1

Time 2

Time 1

Time 1

Penaltis

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void) {
    int q, p, a, b;
    int s1, s2, p1, p2, a1, a2;
    char lx;

    scanf("%d", &q);
    for (p = 0; p  <  q; ++p) {
        s1 = s2 = p1 = p2 = a1 = a2 = 0;
        scanf("%d %c %d", &a, &lx, &b);
        a2 = a;
        s1 += a;
        s2 += b;
        if (a > b) p1 += 3;
        else if (b > a) p2 += 3;
        else {
            ++p1;
            ++p2;
        }
        scanf("%d %c %d", &b, &lx, &a);
        a1 = b;
        s1 += a;
        s2 += b;
        if (a > b) p1 += 3;
        else if (b > a) p2 += 3;
        else {
            ++p1;
            ++p2;
        }
        if (p1 > p2) printf("Time 1\n");
        else if (p2 > p1) printf("Time 2\n");
        else {
            if (s1 - s2 > s2 - s1) printf("Time 1\n");
            else if (s2 - s1 > s1 - s2) printf("Time 2\n");
            else {
                if (a1 > a2) printf("Time 1\n");
                else if (a2 > a1) printf("Time 2\n");
                else printf("Penaltis\n");
            }
        }
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4
1 x 1
2 x 1
2 x 0
2 x 1
1 x 1
2 x 2
3 x 1
3 x 1

Output

x
+
cmd
Time 2
Time 1
Time 1
Penaltis

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>

using namespace std;

int main(void) {
    int q, p, a, b;
    int s1, s2, p1, p2, a1, a2;
    char lx;

    cin >> q;
    for (p = 0; p  <  q; ++p) {
        s1 = s2 = p1 = p2 = a1 = a2 = 0;
        cin >> a >> lx >> b;
        a2 = a;
        s1 += a;
        s2 += b;
        if (a > b) p1 += 3;
        else if (b > a) p2 += 3;
        else {
            ++p1;
            ++p2;
        }
        cin >> b >> lx >> a;
        a1 = b;
        s1 += a;
        s2 += b;
        if (a > b) p1 += 3;
        else if (b > a) p2 += 3;
        else {
            ++p1;
            ++p2;
        }
        if (p1 > p2) cout << "Time 1" << endl;
        else if (p2 > p1) cout << "Time 2" << endl;
        else {
            if (s1 - s2 > s2 - s1) cout << "Time 1" << endl;
            else if (s2 - s1 > s1 - s2) cout << "Time 2" << endl;
            else {
                if (a1 > a2) cout << "Time 1" << endl;
                else if (a2 > a1) cout << "Time 2" << endl;
                else cout << "Penaltis" << endl;
            }
        }
    }
    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
4
1 x 1
2 x 1
2 x 0
2 x 1
1 x 1
2 x 2
3 x 1
3 x 1

Output

x
+
cmd
Time 2
Time 1
Time 1
Penaltis
Advertisements

Demonstration


Previous
#1534 Beecrowd Online Judge Solution 1534 Array 123 Solution in C++, Java, Js and Python
Next
#1540 Beecrowd Online Judge Solution 1540 Energy Planning Solution in C, C++, Java, Js and Python