## Algorithm

Problem Name: beecrowd | 3037

# Playing Darts by Distance

By Pedro S. L. Rey Brazil

Timelimit: 1

John and Mary created their own version of darts, darts by distance. Each one throws 3 darts, choosing how far they will play from the target. In the normal game of darts, a number x is scored by the distance between where the dart hit and the center of the target. In the game of John and Mary it is punctuated xd where d is the distance betwen the shooter and the target.

John asks you to make an algorithm that gives the score given the distance of each turn, returns the winner

## Input

The first line of the entry consists of a N number of test cases. In each test case there will be 6 lines, where the first 3 lines correspond to the pitches of John and the next 3 lines to the pitches of Mary. Each line of a test case consists of two numbers X and D where X is the score and D is the distance

## Output

The output consists of the winner of each test case.

 Input Sample Output Sample 2 1 10 2 1 1 1 10 10 1 0 2 0 10 1 1 10 2 5 1 1 2 1 3 0 MARIA JOAO

## Code Examples

### #1 Code Example with C Programming

```Code - C Programming```

``````
#include <stdio.h>

int main(int argc, char **argv)
{

int n;
unsigned pts[2] = { 0 };

scanf("%d", &n);

int m, j;
while (n--)
{
m = j = 3;
unsigned x, d;
pts[0] = pts[1] = 0;
while (j--)
{

scanf("%u %u", &x, &d);
pts[0] += x * d;

}

while (m--)
{

scanf("%u %u", &x, &d);
pts[1] += x * d;

}

if (pts[0] > pts[1])
puts("JOAO");
else
puts("MARIA");

}

return 0;
}
``````
Copy The Code &

Input

cmd
2 1 10 2 1 1 1 10 10 1 0 2 0 10 1 1 10 2 5 1 1 2 1 3 0

Output

cmd
MARIA JOAO

### #2 Code Example with Java Programming

```Code - Java Programming```

``````
import java.io.IOException;

import java.util.Scanner;
import java.util.Scanner;

public class Main {

public static class jogoDardosMJ {
private int qtdTestes = 0;
private int somatorioPMaria = 0;
private int somatorioPJoao = 0;
private String vencedor = "";

private void setQtdTestes(int qtdTestes) {
this.qtdTestes = qtdTestes;
}

private int getQtdTestes() {
return qtdTestes;
}

public int getSomatorioPJoao() {
return somatorioPJoao;
}

public int getSomatorioPMaria() {
return somatorioPMaria;
}

public void setSomatorioPJoao(int somatorioPJoao) {
this.somatorioPJoao = somatorioPJoao;
}

public void setSomatorioPMaria(int somatorioPMaria) {
this.somatorioPMaria = somatorioPMaria;
}

private void setVencedor(String vencedor) {
this.vencedor = vencedor;
}

private String getVencedor() {
return this.vencedor;
}

private void calcPontosJoao(int dJoao, int xJoao) {
int pontosJoao = (dJoao * xJoao);
this.somatorioPJoao += pontosJoao;
// System.out.println(this.somatorioPJoao);
}

private void calcPontosMaria(int dMaria, int xMaria) {
int pontosMaria = (dMaria * xMaria);
this.somatorioPMaria += pontosMaria;
// System.out.println(this.somatorioPMaria);
}
}

public static void main(String[] args) {
Scanner entradaDados = new Scanner(System.in);
jogoDardosMJ metodos = new jogoDardosMJ();

int qtdTestes = entradaDados.nextInt();
metodos.setQtdTestes(qtdTestes);

for (int i = 0; i  <  metodos.getQtdTestes(); i++) {
for (int j = 0; j  <  3; j++) {
int xJoao = entradaDados.nextInt();
int dJoao = entradaDados.nextInt();
metodos.calcPontosJoao(dJoao, xJoao);
}
for (int j = 0; j  <  3; j++) {
int xMaria = entradaDados.nextInt();
int dMaria = entradaDados.nextInt();
metodos.calcPontosMaria(dMaria, xMaria);
}
if (metodos.getSomatorioPJoao() > metodos.getSomatorioPMaria()) {
metodos.setVencedor("JOAO");
} else {
metodos.setVencedor("MARIA");
}
metodos.setSomatorioPJoao(0);
metodos.setSomatorioPMaria(0);
System.out.println(metodos.getVencedor());
}
entradaDados.close();
}
}
``````
Copy The Code &

Input

cmd
2 1 10 2 1 1 1 10 10 1 0 2 0 10 1 1 10 2 5 1 1 2 1 3 0

Output

cmd
MARIA JOAO

### #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 testes = parseInt(prompt("nmr de testes"));
var pontosjoao = 0;
var pontosmaria = 0;
var somajoao = 0;
var somamaria = 0;
var z;
var j;
var i;

for(z = 0; z  <  testes ; z++){
for( i = 0 ; i  < 3 ; i++){
var x = prompt(" ");
var [a,b] = x.split(' ');
a = parseInt(a);
b = parseInt(b);
pontosjoao = a*b;
somajoao += pontosjoao;

}
for( j = 0 ; j  < 3 ; j++){
var k = prompt(" ");
var [c,d] = k.split(' ');
c = parseInt(c);
d = parseInt(d);
pontosmaria = c*d;
somamaria += pontosmaria;
}

if(somajoao > somamaria){
console.log("JOAO");
somamaria = 0;
somajoao = 0;
} else{
console.log("MARIA");
somamaria = 0;
somajoao = 0;
}

}

``````
Copy The Code &

Input

cmd
2 1 10 2 1 1 1 10 10 1 0 2 0 10 1 1 10 2 5 1 1 2 1 3 0

Output

cmd
MARIA JOAO

### #4 Code Example with Python Programming

```Code - Python Programming```

``````
for _ in range(int(input())):
j=m=0
for joao in range(3):
x=list(map(int,input().split()))
j+=(x[0]*x[1])
for maria in range(3):
x=list(map(int,input().split()))
m+=(x[0]*x[1])
print("MARIA") if m>j else print("JOAO")
``````
Copy The Code &

Input

cmd
2 1 10 2 1 1 1 10 10 1 0 2 0 10 1 1 10 2 5 1 1 2 1 3 0

Output

cmd
MARIA JOAO
Advertisements