Algorithm


Problem Name: beecrowd | 2059

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

Odd, Even or Cheating

 

By Marianne Linhares, UFCG BR Brazil

Timelimit: 1

A new game called Odd, Even or Cheating is currently (OEC) is now one of the most popular games in the world. This game was created when some friends had no internet connection, no cellphone, no computer, and pretty much nothing to do. The game is so popular that is going to happen the mundial championship of OEC and each country of the world will choose a representant to compete in this championship.

The game works like this: it's a two players game, the player 1 chooses between odd or even, then each player chooses a positive integer, if the sum of these number is even and player 1 chose even, then player 1 wins, if the sum is odd and player 2 chose odd, then player 2 wins. If player 1 chooses odd he/she wins when the sum is odd, and player 2 wins when the sum is even. Nothing new, right?

But now there are two more possible moves, player 1 can cheat to make sure that he/she wins independently of the result of the conventional odd or even game, and player 2 can accuse player 1 of cheating. With these additions in the game if player 1 cheats and player 2 accuses him/her of cheating player 2 wins, if player 2 don't accuse and player 1 is cheating then player 1 wins, if player 2 accuses the cheat, but player 1 is not cheating then player 1 wins, if player 1 isn't cheating and player 2 doesn't accuse player 1 then the game will be played as described previously.

You were hired by OECIO (Odd, Even or Cheating International Organization) to develop a program that given an OEC match it determines the winner.

 

Input

 

The input consists of one line with 5 integers: p, j1, j2, r, a. ( 0 ≤ p, r, a ≤ 1 e 1 ≤ j1, j2 ≤ 100).

p is the player 1 choice (if p = 1 then player 1 chooses even, if p = 0 then player 1 chooses odd). j1, j2, represents respectively the numbers that player 1 chose and the number that player 2 chose. r represents if player 1 cheated (if r = 1 then player 1 cheated, if r = 0 then he/she did not), a represents if player 2 accused player 1 of cheating (if a = 1 then he/she did, if a = 0 then he/she did not).

 

Output

 

Print "Jogador 1 ganha!" if player 1 won or "Jogador 2 ganha!" if player 2 won (no quotation marks).

 

 

 

Input Samples Output Samples

1 4 5 0 0

Jogador 2 ganha!

 

 

 

1 4 5 1 0

Jogador 1 ganha!

 

 

 

1 4 5 1 1

Jogador 2 ganha!

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void)

{
    int a, b, c, d, e, sum, x;

    scanf("%i %i %i %i %i", &a, &b, &c, &d, &e);

    sum=b+c;

    if (sum%2==0)
        x=1;

    else
        x=0;

    if (d==0 && e==0)
    {
        if (x==a)
            printf("Jogador 1 ganha!\n");

        else
            printf("Jogador 2 ganha!\n");
    }

    else if (d==0 && e==1)
        printf("Jogador 1 ganha!\n");

    else if (d==1 && e==0)
        printf("Jogador 1 ganha!\n");

    else if (d==1 && e==1)
        printf("Jogador 2 ganha!\n");

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 4 5 0 0

Output

x
+
cmd
Jogador 2 ganha!

#2 Code Example with C++ Programming

Code - C++ Programming


#include<stdio.h>

int main()
{
    int p,j1,j2,r,a,sum,win;
    while(scanf("%d %d %d %d %d",&p,&j1,&j2,&r,&a)!=EOF)
    {
        sum=j1+j2;
        if((sum%2==0 && p==1) || (sum%2!=0 && p==0))win=1;
        else
            win=2;
        if((r==1 && a==0)||(r==0 && a==1))win=1;
        else if(r==1 && a==1) win=2;
        printf("Jogador %d ganha!\n",win);
    }

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 4 5 0 0

Output

x
+
cmd
Jogador 2 ganha!

#3 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var prompt = function(texto) { return lines.shift();};
var inicial = prompt("Digite os Valores").split(" ").map(Number)
var soma,imparpar
const p = inicial[0];
const j1 = inicial[1];
const j2 = inicial[2];
const r = inicial[3];
const a = inicial[4];
soma = j1 + j2
if (soma %2 == 0){
		parimpar = 0; // par
	}else{
		parimpar = 1; // impar
	}
// Ganhador 1
if (p == 1 && parimpar == 0 && r ==0 && a==0){// p == 1 par jogador 1
		console.log("Jogador 1 ganha!");
	}else if (p == 0 && parimpar == 1 && r ==0 && a ==0 ){ // p ==0 impar jogador 1
		console.log("Jogador 1 ganha!");
	}else if (r ==1 && a ==0){// Jogador 1 roubou
		console.log("Jogador 1 ganha!");
	}else if (r == 1 && a == 1){//Acusou o roubo
		console.log("Jogador 2 ganha!");
	}else if (p==1 && parimpar == 1 && r ==0 && a==0){
		console.log("Jogador 2 ganha!");
	}else if (p==0 && parimpar ==0 && r ==0 && a==0){
	    console.log("Jogador 2 ganha!");
	}else if (r ==0 && a ==1){
		console.log("Jogador 1 ganha!");
	}
	
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 4 5 0 0

Output

x
+
cmd
Jogador 2 ganha!

#4 Code Example with Python Programming

Code - Python Programming


p, j1, j2, r, a = input().split()

resultado = (int(j1) + int(j2)) % 2

if((r == '1') and (a == '1')):
    print('Jogador 2 ganha!')

elif((r == '1') or (a == '1')):
    print('Jogador 1 ganha!')

else:
    if(resultado == 0):
        if(p == '1'):
            print('Jogador 1 ganha!')
        else:
            print('Jogador 2 ganha!')
    elif(resultado == int(p)):
        print('Jogador 2 ganha!')
    else:
        print('Jogador 1 ganha!')
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 4 5 0 0

Output

x
+
cmd
Jogador 2 ganha!
Advertisements

Demonstration


Previous
#2058 Beecrowd Online Judge Solution 2058 Triangles and Regular Polygons Solution in C, C++, Java, Js and Python
Next
#2060 Beecrowd Online Judge Solution 2060 Bino's Challenge Solution in C, C++, Java, Js and Python