Algorithm


Problem Name: beecrowd | 2031

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

Rock, Paper, Airstrike

 

By Jeremias Gomes, Universidade de Brasília BR Brazil

Timelimit: 1

Rock, Paper, Airstrike is a very popular children’s game, in which two or more children form a circle and do hand gestures in an attempt to get the victory. The rules are surprisingly complex for a children’s game, but it’s still quite popular around the world.

The games are very simple. Players can choose between the sign of a Rock (fist), the sign of a paper (an open palm), and the signal to the Air Attack (like the paper, but with only the thumb and little finger extended).

A game with two players have the following rules to determine a winner:

  • Airstrike vs. Rock: In this case, the player with Airstrike defeats the player with Rock for obvious reasons.
  • Rock vs. Paper: In this case the player with Rock defeats the one with Paper, because Rock hurts more.
  • Paper vs. Airstrike: In here Airstrike wins because Airstrike always wins and Paper is pathetic.
  • Paper vs. Paper: In this variation both players win because Paper is useless and no one facing Paper can lose.
  • Rock vs. Rock: To this case there is no winner because it depends on what the players decide to do with the Rock and usually do nothing at the end.
  • Airstrike vs. Airstrike: When this happens all players lose due to Mutual Annihilation.

Your task is to write a program that given the choice of two players tell who won the game.

 

Input

 

The input consist of N (1 ≤ N ≤ 1000) test cases. N should be read in the first line of input. Each test case is composed of two lines each containing a string. The first string is the sign chosen by Player 1 and the second string is the sign chosen by the Player 2. These string can be:

  • “ataque”: to represents Airstrike
  • “pedra”: to represents Rock
  • “papel”: tp represents Paper

 

Output

 

The output must be contain:

  • “Jogador 1 venceu”: if Player 1 has won the game
  • “Jogador 2 venceu”: if Player 2 has won the game
  • “Ambos venceram”: if the both have won the game
  • “Sem ganhador”: if there is no winner
  • “Aniquilacao mutua”: if Mutual Annihilation occurs

Each output of a test case must be in one line.

 

 

 

Input Sample Output Sample

2
pedra
pedra
ataque
papel

Sem ganhador
Jogador 1 venceu

 

Code Examples

#2 Code Example with C++ Programming

Code - C++ Programming


#include<;iostream>;
#include<;string>;
using namespace std;

int main() {
    int temp; cin >> temp;
    string A, B;
    while(cin >> A >> B) {
        if (A == "ataque" && B == "ataque") {
            cout << "Aniquilacao mutua" << endl;
        } else if (A == "pedra" && B == "pedra") {
            cout << "Sem ganhador" << endl;
        } else if (A == "papel" && B == "papel") {
            cout << "Ambos venceram" << endl;
        } else if (A == "ataque") {
            cout << "Jogador 1 venceu" << endl;
        } else if (B == "ataque") {
            cout << "Jogador 2 venceu" << endl;
        } else if (A == "pedra") {
            cout << "Jogador 1 venceu" << endl;
        } else if (B == "pedra") {
            cout << "Jogador 2 venceu" << endl;
        } 
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
2 pedra pedra ataque papel

Output

x
+
cmd
Sem ganhador Jogador 1 venceu

#3 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();
for(let i = 0; i  <  number; i++){
  let player1 = lines.shift().trim();
  let player2 = lines.shift().trim();
  
  switch(player1){
    case 'ataque':
      if(player1 == player2){
        console.log("Aniquilacao mutua");
      }
      else{
        console.log("Jogador 1 venceu");
      }
      break;
    case 'pedra':
      if(player1 == player2){
        console.log("Sem ganhador");
      }
      else if(player2 == "ataque"){
        console.log("Jogador 2 venceu");
      }
      else{
        console.log("Jogador 1 venceu");
      }
      break;
    case 'papel':
      if(player1 == player2){
        console.log("Ambos venceram");
      }
      else{
        console.log("Jogador 2 venceu");
      }
      break;
  }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
2 pedra pedra ataque papel

Output

x
+
cmd
Sem ganhador Jogador 1 venceu

#4 Code Example with Python Programming

Code - Python Programming


n = int(input())
while(n > 0):
    n -= 1
    j1 = input()
    j2 = input()
    if(j1 == 'ataque'):
        if(j2 == 'ataque'):
            print('Aniquilacao mutua')
        else:
            print('Jogador 1 venceu')
    elif(j1 == 'papel'):
        if((j2 == 'ataque') or (j2 == 'pedra')):
            print('Jogador 2 venceu')
        else:
            print('Ambos venceram')
    elif(j1 == 'pedra'):
        if(j2 == 'papel'):
            print('Jogador 1 venceu')
        if(j2 == 'ataque'):
            print('Jogador 2 venceu')
        elif(j2 == 'pedra'):
            print('Sem ganhador')
Copy The Code & Try With Live Editor

Input

x
+
cmd
2 pedra pedra ataque papel

Output

x
+
cmd
Sem ganhador Jogador 1 venceu
Advertisements

Demonstration


Previous
#2029 Beecrowd Online Judge Solution 2029 Honey Reservoir Solution in C, C++, Java, Js and Python
Next
#2057 Beecrowd Online Judge Solution 2057 Time Zone Solution in C, C++, Java, Js and Python