Algorithm Analysis
Let's write two conditions. In the first one, we'll check if there is an even number among the three numbers. In the second one, we'll check if there is an odd number among the three numbers. If both conditions are true, then we'll output "YES".
Algorithm Implementation
We read the input data. We'll set the variable flag to 0. If there is an even number among the three input numbers, then we'll increase flag by 1. Next, if there is an odd number among the three numbers, we'll also increase flag by 1.
If one of the input numbers is a negative odd number, then the remainder of its division by 2 equals -1, not 1. Therefore, it's simpler to move to solving the problem on non-negative integers, taking the absolute value of the input values.
scanf("%d %d %d",&a,&b,&c);
flag = 0;
if (a < 0) a = -a;
if (b < 0) b = -b;
if (c < 0) c = -c;
if ((a % 2 == 0) || (b % 2 == 0) || (c % 2 == 0)) flag++;
if ((a % 2 == 1) || (b % 2 == 1) || (c % 2 == 1)) flag++;
if (flag == 2)
printf("YES\n");
else
printf("NO\n");If both conditions are true, then the variable flag will have the value 2. We output the result depending on the value of flag.
Second Solution. The problem can be solved using a single complex condition.
scanf("%d %d %d",&a,&b,&c);
if (a < 0) a = -a;
if (b < 0) b = -b;
if (c < 0) c = -c;
if (((a % 2 == 0) || (b % 2 == 0) || (c % 2 == 0)) && ((a % 2 == 1) || (b % 2 == 1) || (c % 2 == 1)))
printf("YES\n");
else
printf("NO\n");Java Implementation
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
int a = con.nextInt();
int b = con.nextInt();
int c = con.nextInt();
int flag = 0;
if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) flag++;
if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0) flag++;
if (flag == 2)
System.out.println("YES");
else
System.out.println("NO");
con.close();
}
}Python Implementation
a,b,c = map(int,input().split())
flag = 0
if ((a % 2 == 0) or (b % 2 == 0) or (c % 2 == 0)) : flag += 1
if ((a % 2 == 1) or (b % 2 == 1) or (c % 2 == 1)) : flag += 1
if (flag == 2) :
print("YES")
else :
print("NO")