Problem Link:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Author: Soumyadeep Pal
Tester: Danny Mittal
Editorialist: Ritesh Gupta
DIFFICULTY:
Cakewalk
PREREQUISITES:
NONE
PROBLEM:
You are given a number x (1 \leq x \leq 300) defining the strength of the problem. A problem is called :
-
Easy if 1 \leq x \lt 100
-
Medium if 100 \leq x \lt 200
-
Hard if 200 \leq x \leq 300
Find the category to which problem belongs.
EXPLANATION:
This is a standard problem for conditional statements. We need to find the difficulty of the problem based on the above conditions. As the given number x is bounded within [1, 300] , we can write the conditions like this -
- if (x < 100) → Easy
- else if (x < 200) → Medium
- else → Hard
TIME COMPLEXITY:
O(1) for each testcase.
CODE:
Setter (C++)
#include using namespace std; void solve(int tc) { int n; cin >> n; if (n < 100) cout << "Easy\n"; else if (n < 200) cout << "Medium\n"; else cout <> t; for (int i = 1; i <= t; i++) solve(i); return 0; }
Tester (Kotlin)
import java.io.BufferedInputStream fun main(omkar: Array) { val jin = FastScanner() repeat(jin.nextInt(50)) { val x = jin.nextInt(300) println(when { x < 100 -> "Easy" x < 200 -> "Medium" x <= 300 -> "Hard" else -> "Landslide" }) } jin.endOfInput() } class InvalidInputException(message: String): Exception(message) class FastScanner { private val BS = 1 shl 16 private val NC = 0.toChar() private val buf = ByteArray(BS) private var bId = 0 private var size = 0 private var c = NC private var `in`: BufferedInputStream? = null private val validation: Boolean constructor(validation: Boolean) { this.validation = validation `in` = BufferedInputStream(System.`in`, BS) } constructor() : this(true) private val char: Char private get() { while (bId == size) { size = try { `in`!!.read(buf) } catch (e: Exception) { return NC } if (size == -1) return NC bId = 0 } return buf[bId++].toChar() } fun validationFail(message: String) { if (validation) { throw InvalidInputException(message) } } fun endOfInput() { if (char != NC) { validationFail("excessive input") } if (validation) { System.err.println("input validated") } } fun nextInt(from: Int, to: Int, endsLine: Boolean = true) = nextLong(from.toLong(), to.toLong(), endsLine).toInt() fun nextInt(to: Int, endsLine: Boolean = true) = nextInt(1, to, endsLine) fun nextLong(endsLine: Boolean): Long { var neg = false c = char if (c !in '0'..'9' && c != '-' && c != ' ' && c != '\n') { validationFail("found character other than digit, negative sign, space, and newline, character code = ${c.toInt()}") } if (c == '-') { neg = true c = char } var res = 0L while (c in '0'..'9') { res = (res shl 3) + (res shl 1) + (c - '0').toLong() c = char } if (endsLine) { if (c != '\n') { validationFail("found character other than newline, character code = ${c.toInt()}") } } else { if (c != ' ') { validationFail("found character other than space, character code = ${c.toInt()}") } } return if (neg) -res else res } fun nextLong(from: Long, to: Long, endsLine: Boolean = true): Long { val res = nextLong(endsLine) if (res !in from..to) { validationFail("$res not in range $from..$to") } return res } fun nextLong(to: Long, endsLine: Boolean = true) = nextLong(1L, to, endsLine) }
Editorialist (C++)
#include using namespace std; int main() { int t; cin >> t; while(t--) { int n; cin >> n; if (n < 100) { cout << "Easy\n"; } else if (n < 200) { cout << "Medium\n"; } else { cout << "Hard\n"; } } return 0; }