At least one condition out of two#8892

At least one condition out of two (Editorial)

Algorithm Analysis

We will count the number of conditions met in the variable flag. Initially, we assign flag = 0.

If flag > 0, then at least one of the conditions is met, we print "YES". Otherwise, we print "NO".

Algorithm Implementation

Read the input number .

scanf("%d", &n);

Check the two conditions. If a condition is met, then we increase flag by 1.

flag = 0;
if (n % 2 != 0) flag++;
if (n >= 100 && n <= 999) flag++;

Depending on the value of the variable flag, we print the corresponding answer.

if (flag > 0) puts("YES");
else puts("NO");

Java Implementation

import java.util.*;

public class Main
{
    public static void main(String[] args) 
    {
        Scanner con = new Scanner(System.in);
        int n = con.nextInt();
        int flag = 0;
        if (n % 2 != 0) flag++;
        if (n >= 100 && n <= 999) flag++;
        
        if (flag > 0) System.out.println("YES");
        else System.out.println("NO");
        
        con.close();
    }
}

Python Implementation

n = int(input())
flag = 0
if n % 2 != 0: flag += 1
if n >= 100 and n <= 999: flag += 1

if flag > 0: print("YES")
else: print("NO")