PROBCAT - Editorial

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 :

  1. Easy if 1 \leq x \lt 100

  2. Medium if 100 \leq x \lt 200

  3. 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;
}

i use same technique but it’s showing my ans is wrong
please halp me
#include
using namespace std;

int main() {
int tc;
cin>>tc;
while(tc–)
{
int x; cin>>x;
if(x<100)
{
cout<<“Easy\n”;
}
else if(x<200)
{
cout<<“Medium\n”;
}
else
{
cout<<“Hard”;
}
}
return 0;
}
this is my code where i get worng

in while condition do tc-- instead of tc-
and a new line is req in cout<<“Hard”;

1 Like

Thanks for correcting me

only 2 testcases are clear and the other two is not clearing please help

#include
using namespace std;

int main() {
int T;
cin>>T;
while(T–){

    int x;
    cin>>x;
    if(x>=1 && x<100) cout<<"Easy\n";
    else if(x>=100 && x<200) cout<<"Medium\n";
    else if(x>=200 && x<=300)cout<<"Hard\n";
}
return 0;

}

The third and fourth test cases have been added and they appear to be broken @admin

The last successful submission was this one which had 2 test cases - 15 minutes later there were 4 test cases and no-one has had AC since then.

Apologies. Should be fixed now.