Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1542

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

Reading Books

 

By Normandes Jr, UFU BR Brazil

Timelimit: 3

You've started competing against your friend to see who can read more books in less time. Your friend used to read much more fast than you, until the day you realized that he'd read only small books.

So, you've decided counting how many pages each book has. And decided to increase the amount of pages read per day. Now you read 5 pages per day and finish 16 days before, if you were reading 3 pages per day. In this case, how many pages has the book?

 

Input

 

The input has many test cases. Each test has tree numbers Q (0 < Q < 20), D (0 < D < 20) and P (0 < P < 20) separated by one blank space. Q means the amount of pages read per day. D is the number of days you could speed up, if you were reading the amount of pages P. An unique 0 (zero) value means end of inputs.

 

Output

 

For each test case it should be printed how many pages the book has. Use plural appropriately in Portuguese ("pagina" or "paginas"). This number should be an integer and truncated - no rounding.

 

 

 

Sample Input Sample Output

3 16 5
0

120 paginas

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void) {
    int A, B, C, N;

    while (scanf("%d", &A) && A != 0) {
        scanf("%d %d", &B, &C);
        N = (int)((A * B * C) / (C - A));
        if (N == 1) printf("1 pagina\n");
        else printf("%d paginas\n", N);
    }

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

Input

x
+
cmd
3 16 5
0

Output

x
+
cmd
120 paginas

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>

using namespace std;

int main(void) {
    int A, B, C, N;

    while (cin >> A && A != 0) {
        cin >> B >> C;
        N = int((A * B * C) / (C - A));
        if (N == 1) cout << "1 pagina" << endl;
        else cout << N << " paginas" << endl;
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 16 5
0

Output

x
+
cmd
120 paginas

#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;
        int Q, D, P, pag;
        while (!(l = in.readLine()).equals("0")) {
            String[] parameters = l.split("\\s");
            Q = Integer.parseInt(parameters[0]);
            D = Integer.parseInt(parameters[1]);
            P = Integer.parseInt(parameters[2]);
            pag = (int) (P * D * Q) / (P - Q);
            String ouput = pag + " pagina";
            ouput += (pag == 1) ? "" : "s";
            out.println(ouput);
        }
        out.close();
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 16 5
0

Output

x
+
cmd
120 paginas

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

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

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

	const helper = (line = "") => line.split(" ", 3).map(value => Number.parseInt(value, 10))
	const nextLine = lineReader.nextLine.bind(lineReader, helper)

	while (lineReader.hasNextLine()) {
		const [Q, D = 0, P = 0] = await nextLine()

		if (Q === 0) break
		const bookPagesQuantity = Math.floor((Q * D * P) / (P - Q))

		output.push(
			bookPagesQuantity === 1 ?
				`${bookPagesQuantity} pagina` :
				`${bookPagesQuantity} paginas`
		)
	}

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

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

main()

Copy The Code & Try With Live Editor

Input

x
+
cmd
3 16 5
0

Output

x
+
cmd
120 paginas

#5 Code Example with Python Programming

Code - Python Programming


while True:
    e = [int(x) for x in str(input()).split()]
    if e[0] == 0: break
    q = e[0]
    d = e[1]
    p = e[2]
    n = int((q * d * p) / (p - q))
    if n == 1: print('1 pagina')
    else: print('{} paginas'.format(n))

Copy The Code & Try With Live Editor

Input

x
+
cmd
3 16 5
0

Output

x
+
cmd
120 paginas
Advertisements

Demonstration


Previous
#1541 Beecrowd Online Judge Solution 1541 Building Houses Solution in C++, Java, Js and Python
Next
#1546 Beecrowd Online Judge Solution 1546 Feedback Solution in C, C++, Java, Js and Python