Algorithm
problem Link : https://www.codechef.com/JAN231D/problems/NEGPROD
Problem
Chef is given three numbers and .
He wants to find whether he can select exactly two numbers out of these such that the product of the selected numbers is negative.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of three integers and , the given numbers.
Output Format
For each test case, output YES
if Chef can select exactly two numbers out of these such that the product of the selected numbers is negative, NO
otherwise.
You may print each character in uppercase or lowercase. For example, the strings NO
, no
, No
, and nO
, are all considered identical.
Constraints
Sample 1:
5 1 5 7 -5 0 4 6 -1 0 -3 -5 -2 0 0 -4
NO YES YES NO NO
Explanation:
Test case : There exists no way to select two numbers such that their product is negative.
Test case : The product of and is which is negative.
Test case : The product of and is which is negative.
Test case : There exists no way to select two numbers such that their product is negative.
Test case : There exists no way to select two numbers such that their product is negative.
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include<stdio.h>
int main()
{
int t,x,y,z;
scanf("%d",&t);
while(t--)
{
scanf("%d %d %d",&x,&y,&z);
if(x*y<0 || y*z < 0 || x*z<0) printf("Yes\n");
else printf("No\n">;
}
}
Copy The Code &
Try With Live Editor
Input
1 5 7
-5 0 4
-3 -5 -2
Output
YES
YES
NO
NO
Demonstration
CodeChef solution MINN00 - Minimum Number of Ones Codechef solution in C,C++