Each condition of two#8893

Each condition of two (Editorial)

Algorithm Analysis

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

If flag = 2, then both conditions are met, we output YES. Otherwise, we output NO.

Algorithm Implementation

Read the input number .

scanf("%d", &n);

We check two conditions. If a condition is met, then we increase flag by 1.

flag = 0;
if (n % 3 == 0) flag++;
if (n % 2 == 0 && ((n >= 10 && n <= 99) || (n >= -99 && n <= -10)))
    flag++;

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

if (flag == 2) 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 % 3 == 0) flag++;
        if (n % 2 == 0 && ((n >= 10 && n <= 99) || (n >= -99 && n <= -10))) flag++;
        if (flag == 2) System.out.println("YES");
        else System.out.println("NO");
        con.close();
    }
}

Python Implementation

n = int(input())

flag = 0
if n % 3 == 0: flag += 1
if n % 2 == 0 and ((n >= 10 and n <= 99) or (n >= -99 and n <= -10)): flag += 1

if flag == 2: print("YES")
else: print("NO")