Algorithm


Problem Name: beecrowd | 1914

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

Whose Turn Is It?

 

By Jadson José Monteiro Oliveira, Faculdade de Balsas BR Brazil

Timelimit: 1

Hopscotch is probably the game where townhouse's children more have fun, however the game has caused a good time for discussion and crying in children who practice it. The cause of the disorder is to decide who will be the next to jump, but recently Quico (The Genius!) had a great idea for to solve the problem. Basically the game can only to be played every two players in one turn and to choose the next player Quico indicated to use the traditional method even or odd, where both players report one number and if the sum these numbers is even, the player that choose PAR win or vice verse. However the use that method has left the Quico crazy, crazy, crazy... And for that reason he asked for your help, asked you a program that given the name of the players, their respective choices (PAR or IMPAR) and the numbers, tell who was the winner.

 

Input

 

The first line of input contains a single integer QT (1 ≤ QT ≤ 100), indicating the number of following test cases. Each test case contains two lines. In first line will be told the name of the player 1 followed by his choice, “PAR” or “IMPAR”, and after the name of the player 2 followed by his choice, “PAR” or “IMPAR”. In second line of test case, contains two integer number N (1 ≤ N ≤ 10⁹) and M (1 ≤ M ≤ 10⁹), representing respectively the numbers chosen by players 1 and player 2. It it garanteed that player 1 choice's (PAR or IMPAR) will be differ from choice of player 2 (PAR or IMPAR) and that the name of the players consist only of letters and will not exceed 100 characters.

 

Output

 

For each test case, print a single line containing the name of winner player.

 

 

 

Input Sample Output Sample

4

Quico PAR Chiquinha IMPAR

9 7

Dami PAR Marcus IMPAR

12 3

Dayran PAR Conrado IMPAR

3 1000000000

Popis PAR Chaves IMPAR

2 7

Quico

Marcus

Conrado

Chaves

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
 
using namespace std;
 
int main() {

     string str[4];
     int t;
     int m,n;
     cin>>t;
     while(t-->0)
     {
         cin>>str[0]>>str[1]>>str[2]>>str[3];
         cin>>m>>n;
         m=m+n;
         if(m%2==0)
         {
             if(str[1]=="PAR")
             cout << str[0] << endl;
             else
             cout << str[2] << endl;
         }
         if(m%2!=0)
         {
             if(str[1]=="IMPAR")
             cout << str[0] << endl;
             else
             cout << str[2] << endl;
         }
     }
 
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4 Quico PAR Chiquinha IMPAR 9 7 Dami PAR Marcus IMPAR 12 3 Dayran PAR Conrado IMPAR 3 1000000000 Popis PAR Chaves IMPAR 2 7

Output

x
+
cmd
Quico Marcus Conrado Chaves

#2 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
const number = lines.shift();
let sum = 0;

for(let i = 0; i  <  number; i++){
  let [player1, jogada1, player2, jogada2] = lines.shift().trim().split(" ");
  let [a , b] = lines.shift().split(" ");

  sum = parseInt(a) + parseInt(b);

  if( sum % 2 == 0){
    jogada1 == "PAR" ? console.log(player1) : console.log(player2);
  }
  else{
    jogada1 == "IMPAR" ? console.log(player1) : console.log(player2);
  }

  sum = 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4 Quico PAR Chiquinha IMPAR 9 7 Dami PAR Marcus IMPAR 12 3 Dayran PAR Conrado IMPAR 3 1000000000 Popis PAR Chaves IMPAR 2 7

Output

x
+
cmd
Quico Marcus Conrado Chaves
Advertisements

Demonstration


Previous
#1901 Beecrowd Online Judge Solution 1901 Butterflies Solution in C, C++, Java, Js and Python
Next
#1920 Beecrowd Online Judge Solution 1920 Fountain of Desires Solution in C, C++, Java, Js and Python