SPISET - Editorial

Practice
Contest

Author: Mayur Ray
Tester: Tharun Chowdary
Editorialist: Mayur Ray

DIFFICULTY:

CAKEWALK

PREREQUISITES:

None

PROBLEM:

You’re giving the contest in your computer. For your computer to not die during the contest, it needs at least 30% charge now, or there should be electricity in your home. Given the conditions, are you all set for the contest?

QUICK EXPLANATION:

If there’s at least 30% battery charge or electricity in the home, then it’s “All Set”, else “Help my computer”.

EXPLANATION:

There are only two conditions that we have to check :

  • if the current battery charge is at least 30% or not, &
  • if there’s electricity in the home or not.

The question mentions that it needs at least 30% charge now, or there should be electricity. If any of the conditions is true or both are true, then we can print “All set”, otherwise if none satisfies, we print “Help my computer”.
Logical OR (||) operator is the most appropriate thing to use here.

TIME COMPLEXITY:

O(1)

SOLUTIONS:

Setter's & Editorialist's Solution
#include <iostream>
using namespace std;
int main()
{
    int c, e;
    cin >> c >> e;
    if (c >= 30 || e == 1)
    {
        cout << "All set";
    }
    else
    {
        cout << "Help my computer";
    }
    return 0;
}
Tester's Solution
import java.util.*;

class Solution {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

        int C = sc.nextInt(), E = sc.nextInt();
        boolean isReady = (C >= 30 || E == 1);
        System.out.println(isReady ? "All set" : "Help my computer");

        sc.close();
    }

}