Algorithm


Problem Name: beecrowd | 2547

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

Roller Coaster

 

By Flávio Zavan, UFPR BR Brazil

Timelimit: 1

Everyone in Nlogônia is really excited with the opening of Ricardo Barreiro World, the newest amusement park in the country. Its roller coaster, the fastest in the continent, is being widely advertised on TV and Radio. It’s the attraction everyone, from kids to grandmas, wants to ride.

Unfortunately, some restrictions were imposed by the government during the attraction’s homologation. For safety reasons, there is a minimum and a maximum height people must have to ride the roller coaster.

In the inauguration day, every guest filled a register in which they indicated their heights. In order to reduce lines and optimize the operation, you were hired to write a program that, given the number of guests, the minimum and maximum allowed height, and the height of every guest, determine how many guests are allowed to ride the roller coaster.

 

Input

 

The input contains several test cases. The first line of each test case contains three integers N (1 ≤ N ≤ 100), Amin and Amax (50 ≤ AminAmax ≤ 250), the number of guests, the minimum and the maximum allowed height, respectively, in centimeters.

Each of the next N lines contains an integer (50 ≤ Ai ≤ 250), the height of the i-th guest, in centimeters.

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

 

Output

 

For each test case, print a single line containing the number of guests allowed to ride the roller coaster.

 

 

 

Input Sample Output Sample

8 160 182
160
182
183
159
250
170
172
173

5

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void)

{
    int a, b, i, n, count;

    while (scanf("%i %i %i", &n, &a, &b) != EOF)
    {
        int arr[n];

        count=0;

        for (i = 0; i  <  n; ++i)
            scanf("%i", &arr[i]);

        for (i = 0; i  <  n; ++i)
        {
            if (arr[i] >= a && arr[i] <= b)
                ++count;
        }

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

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

Input

x
+
cmd
8 160 182 160 182 183 159 250 170 172 173

Output

x
+
cmd
5

#2 Code Example with C++ Programming

Code - C++ Programming


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

int main(){
    int n, n1, amin, amax, permited = 0;
    while(cin >> n >> amin >> amax){
        while(n--){
            cin >> n1;
            if (n1 >= amin and n1  < = amax) {
                permited ++;
            }
    }
        cout << permited << endl;
        permited = 0;
    }
    

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

Input

x
+
cmd
8 160 182 160 182 183 159 250 170 172 173

Output

x
+
cmd
5

#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);
		while(sc.hasNext()) {
			int n, min, max, altura, conta=0;
			n = sc.nextInt();
			min = sc.nextInt();
			max = sc.nextInt();
			for (int x = 0 ; x  <  n ; x++) {
				altura = sc.nextInt();
				if (altura >= min && altura >= 50 && altura  < = max && altura <= 250 && min <= max && min >= 50 && max <= 250)
					conta++;
			}
			System.out.println(conta);
		}
		sc.close();
	}
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
8 160 182 160 182 183 159 250 170 172 173

Output

x
+
cmd
5

#4 Code Example with Javascript Programming

Code - Javascript Programming


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) break // EOFile Condition

		let countAvailableVisitors = 0
		const [N, min, max] = line
			.split(" ", 3)
			.map(value => Number.parseInt(value, 10))

		for (let index = 0; index  <  N; index += 1) {
			const visitorHeight = Number.parseInt(await lineReader.nextLine(), 10)
			if (min <= visitorHeight && visitorHeight <= max) countAvailableVisitors += 1
		}

		output.push(countAvailableVisitors)
	}

	if (lineReader.hasNextLine()) lineReader.close()
	console.log(output.join("\n"))
}

main()

Copy The Code & Try With Live Editor

Input

x
+
cmd
8 160 182 160 182 183 159 250 170 172 173

Output

x
+
cmd
5

#5 Code Example with Python Programming

Code - Python Programming


while True:
    try:
        n, amin, amax = [int(x) for x in input().split()]
        t = 0
        while n:
            n -= 1
            i = int(input())
            if i >= amin and i <= amax:
                t += 1
        print(t)

    except EOFError:
        break
Copy The Code & Try With Live Editor

Input

x
+
cmd
8 160 182 160 182 183 159 250 170 172 173

Output

x
+
cmd
5
Advertisements

Demonstration


Previous
1546 Beecrowd Online Judge solution Feedback adhoc solution in C, C++
Next
#2548 Beecrowd Online Judge Solution 2548 3D Virtual Museum Solution in C, C++, Java, Js and Python