Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1397

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

Game of The Greatest

 

By Lucas Hermann Negri, UDESC Brasil

Timelimit: 1

Og loves to play with his children. His favorite game is the game of the greatest, invented by himself. This hobby (there was a lot of available time to play in the cavemen's era) is played by two players, Og and one of his children. The rules of the game are as follows: First, the players choose the number of rounds of the match. During a round, each player yells a number between 0 and 10. The player who yells the greatest number scores one point (in case of a tie, no one scores). After all the rounds, the points are counted and the player who has the greater score wins.

Og and his children really like this game, but they usually get lost doing the math. Will you help Og to determine the final score?

 

Input

 

The input consists of several test cases (matches). Each test case starts with an integer N (1 ≤ N ≤ 10) that describes the number of rounds of the match. The value N = 0 indicates the end of the input, and should not be processed. The next N lines contain two integers A and B each (0 ≤ A, B ≤ 10). A is the number yelled by the first player during the round, and B is the number yelled by the second player during the round.

 

Output

 

The output must contain one line for each test case. This line contains the players' score, separated by a single space.

 

 

 

Sample Input Sample Output

3
5 3
8 2
5 6
2
5 5
0 0
0

2 1
0 0

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void) {
    int q, i, a, b, x, y;
    while (scanf("%d", &q) && q != 0) {
        a = b = 0;
        for (i = 0; i  <  q; ++i) {
            scanf("%d %d", &x, &y);
            if (x > y) ++a;
            else if (y > x) ++b;
        }
        printf("%d %d\n", a, b);
    }
    return 0;
}


Copy The Code & Try With Live Editor

Input

x
+
cmd
3
5 3
8 2
5 6
2
5 5
0 0
0

Output

x
+
cmd
2 1
0 0

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>

using namespace std;

int main(void) {
    int q, i, a, b, x, y;
    while (cin >> q && q != 0) {
        a = b = 0;
        for (i = 0; i  <  q; ++i) {
            cin >> x >> y;
            if (x > y) ++a;
            else if (y > x) ++b;
        }
        cout << a << " " << b << endl;
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
5 3
8 2
5 6
2
5 5
0 0
0

Output

x
+
cmd
2 1
0 0

#3 Code Example with Java Programming

Code - Java Programming


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
   static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException {
		String l;
		String[] p;
		int N, A, B, ai, bi;
		while (!(l = read()).equals("0")) {
			N = Integer.parseInt(l);
			ai = 0;
			bi = 0;
			while (N-- > 0) {
				p = read().split("\\s");
				A = Integer.parseInt(p[0]);
				B = Integer.parseInt(p[1]);
				if (A > B) {
					ai++;
				} else if (B > A) {
					bi++;
				}
			}
			out.println(ai + " " + bi);
		}
		out.close();
	}

	private static String read() throws IOException {
		return in.readLine();
	}
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
5 3
8 2
5 6
2
5 5
0 0
0

Output

x
+
cmd
2 1
0 0

#4 Code Example with Javascript Programming

Code - Javascript Programming


//// READING FILE | STREAMS ////
const { createReadStream } = require("node:fs")
const { createInterface } = require("node:readline")

class LineReader {
	/**
	 * @param {import("node:fs").PathLike} path
	 * @param {BufferEncoding} encoding
	 * @return {import("node:readline").ReadLine}
	 */
	static createReadLineInterface(path, encoding = "utf8") {
		const readStreamOptions = {
			encoding: encoding,
			flags: "r",
			emitClose: true,
			autoClose: true
		}

		return createInterface({
			input: createReadStream(path, readStreamOptions),
			crlfDelay: Infinity,
			terminal: false
		})
	}

	/**
	 * @param {import("node:fs").PathLike} path
	 * @param {BufferEncoding} encoding
	 */
	static create(path, encoding) {
		const RLI = LineReader.createReadLineInterface(path, encoding)

		let EOF = false

		const nextLineGenerator = (async function* () {
			for await (const line of RLI)
				yield line
		})()

		RLI.once("close", () => { EOF = true })

		return {
			hasNextLine: () => !EOF,
			nextLine: async (/** @type {unknown} */ fn) => {
				const { value } = (await nextLineGenerator.next())
				return (typeof fn === "function") ? fn(value) : value
			},
			close: () => RLI.close()
		}

	}
}


async function main() {
	const output = []

	const PATH = "/dev/stdin"
	const ENCODING = "utf8"

	const lineReader = LineReader.create(PATH, ENCODING)

	while (lineReader.hasNextLine()) {
		const line = await lineReader.nextLine()

		if (Boolean(line) === false || line === "0") break

		const N = Number.parseInt(line, 10)
		const placar = { pA: 0, pB: 0 }

		for (let i = 0; i  <  N; i += 1) {
			const [A, B] = (await lineReader.nextLine())
				.split(" ", 2)
				.map(value => Number.parseInt(value, 10))

			if (A > B) { placar.pA += 1 }
			else if (B > A) { placar.pB += 1 }
		}

		output.push(`${placar.pA} ${placar.pB}`)
	}

	if (lineReader.hasNextLine())
		lineReader.close()

	console.log(output.join("\n"))
}

main()
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
5 3
8 2
5 6
2
5 5
0 0
0

Output

x
+
cmd
2 1
0 0

#5 Code Example with Python Programming

Code - Python Programming


while True:
    try:
        n = int(input())
        if n == 0: break
        j1 = j2 = 0
        for i in range(n):
            e = str(input()).split()
            a = int(e[0])
            b = int(e[1])
            if a > b: j1 += 1
            elif b > a: j2 += 1
        print(j1, j2)
    except EOFError:
        break
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
5 3
8 2
5 6
2
5 5
0 0
0

Output

x
+
cmd
2 1
0 0
Advertisements

Demonstration


Previous
#1387 Beecrowd Online Judge Solution 1387 Og Solution in C, C++, Java, Js and Python
Next
#1403 Beecrowd Online Judge Solution 1403 Grandpa is Famous Solution in C, C++, Java, Js and Python