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 NOnoNo, and nO, are all considered identical.

Constraints

  • 1≤�≤1000
  • −10≤�,�,�≤10

Sample 1:

Input
 
Output
 
5
1 5 7
-5 0 4
6 -1 0
-3 -5 -2
0 0 -4
NO
YES
YES
NO
NO

Explanation:

Test case 1: There exists no way to select two numbers such that their product is negative.

Test case 2: The product of −5 and 4 is −5⋅4=−20 which is negative.

Test case 3: The product of 6 and −1 is 6⋅(−1)=−6 which is negative.

Test case 4: There exists no way to select two numbers such that their product is negative.

Test case 5: 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

x
+
cmd
5
1 5 7
-5 0 4 6 -1 0
-3 -5 -2 0 0 -4

Output

x
+
cmd
NO
YES
YES
NO
NO
Advertisements

Demonstration


CodeChef solution MINN00  - Minimum Number of Ones Codechef solution in C,C++

Previous
CodeChef solution FLOW007 - Reverse The Number Codechef solution in C,C++
Next
CodeChef solution BULLET - Mario and Bullet Codechef solution in C,C++