Algorithm


Problem Name: beecrowd | 2543

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

UFPR Gaming

 

By Ricardo Oliveira, UFPR BR Brazil

Timelimit: 1

Like many Computer Science students, you like to play the most popular electronic games nowadays: Liga of Legendas (LOL) and Contra-Strike (CS). Although you also play LOL, what you really like to do is to use all your skills to defeat the terrorist forces in Contra-Strike! You are so good at combating terror that you are often compared with the president of the USA who announced the capture of a famous real-life terrorist.

Since your skills are beyond compare, videos of your matches (your famous gameplays) appears often in UFPR Gaming, a webpage that publishes gameplays from the students of our university.

The page publishes many videos every day. Thus, it may be hard to find and count all your videos published already. However, since you are also a programmer, you decided to write a computer program to help you with this task. Given the list of gameplays published by the page, determine how many of them are videos of you playing Contra-Strike.

 

Input

 

The input contains several test cases. The first line of each test case contains two integers N and I (1 ≤ N ≤ 104, 1000 ≤ I ≤ 9999), the number of gameplays published by the page and your university ID, respectively.

The next N lines describe the published videos. Each gameplay is described by two integers i and j (1000 ≤ i ≤ 9999, j=0 or 1), where i is the author’s university ID and j=0 if the gameplay is a Contra-Strike one, or j=1 if it is a Liga of Legendas one.

The input ends with end-of-file (EOF).

 

Output

 

For each test case, print a single line containing a number indicating how many videos of you playing Contra-Strike were published by the page.

 

 

 

Input Sample Output Sample

7 5558
5693 1
5558 0
6009 1
5558 1
1566 0
5558 0
8757 1

2

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void)

{
    int i, j, n, id, count, g, ID;

    while (scanf("%i %i", &n, &id) != EOF)
    {
        count=0;

        for (i = 0; i  <  n; ++i)
        {
            scanf("%i %i", &ID, &g);

            if (ID == id && g == 0)
                ++count;
        }

        printf("%i\n", count);
    }

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

Input

x
+
cmd
7 5558 5693 1 5558 0 6009 1 5558 1 1566 0 5558 0 8757 1

Output

x
+
cmd
2

#2 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
using namespace std;

int main(void)
{
    int n, a;

    while(cin >> n >> a){
        int con = 0;

        for(int i = 0, b, c; i  <  n; i++){
            cin >> b >> c;

            if(b == a and !c)
                con++;
        }
        cout << con << endl;
    }

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

Input

x
+
cmd
7 5558 5693 1 5558 0 6009 1 5558 1 1566 0 5558 0 8757 1

Output

x
+
cmd
2

#3 Code Example with Java Programming

Code - Java Programming


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//sc.useLocale(Locale.ENGLISH);
		//Locale.setDefault(new Locale("en", "US"));

		while(sc.hasNext()){
			
			int n = sc.nextInt();
			int facul = sc.nextInt();
			int entraf = 0;
			int game = 0;
			int contacs = 0;
			
			for (int i = 0 ; i  <  n ; i++){
				entraf = sc.nextInt();
				game = sc.nextInt();
				if (entraf==facul)
					if (game==0)
						contacs++;
			}
			System.out.println(contacs);
		}
		sc.close();
	}
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
7 5558 5693 1 5558 0 6009 1 5558 1 1566 0 5558 0 8757 1

Output

x
+
cmd
2

#4 Code Example with Javascript Programming

Code - Javascript Programming


const { createReadStream } = require("node:fs")
const { createInterface } = require("node:readline")

//// READING FILE | STREAMS ////

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()
		}

	}
}

const MyGamesEnum = Object.freeze({
	"CS": 0,
	"LOL": 1
})

//// MAIN ////

async function main() {
	const PATH = "/dev/stdin"
	const ENCODING = "utf8"

	const output = []
	const lineReader = LineReader.create(PATH, ENCODING)

	while (lineReader.hasNextLine()) {
		const line = await lineReader.nextLine()
		if (Boolean(line) === false) break

		const [N, M] = line
			.split(" ", 2)
			.map(value => Number.parseInt(value, 10))

		let myPublishedCSGameplays = 0

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

			if (i === M && j === MyGamesEnum.CS)
				myPublishedCSGameplays += 1
		}

		output.push(myPublishedCSGameplays)
	}

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

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

main()
Copy The Code & Try With Live Editor

Input

x
+
cmd
7 5558 5693 1 5558 0 6009 1 5558 1 1566 0 5558 0 8757 1

Output

x
+
cmd
2

#5 Code Example with Python Programming

Code - Python Programming


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

Input

x
+
cmd
7 5558 5693 1 5558 0 6009 1 5558 1 1566 0 5558 0 8757 1

Output

x
+
cmd
2
Advertisements

Demonstration


Previous
#2542 Beecrowd Online Judge Solution 2542 Iu-Di-Oh! Solution in C, C++, Java, Js and Python
Next
#2544 Beecrowd Online Judge Solution 2544 Kage Bunshin no Jutsu Solution in C, C++, Java, Js and Python