PROBLEM 45
Medium

Opposite Signs

Programming Basics · C++

</>
STATUS Not solved

TASK

Problem

#45

Two integers `a` and `b` are given. Print `YES` if they have opposite signs; otherwise print `NO`.

EXAMPLE

Example

Input
-2 3
Output
YES

LIMITS

Constraints

All values are integers with magnitude at most 10^9.
📖
LEARN Theory for this problem
+

Logical AND `&&`, OR `||`, and negation `!` combine boolean conditions. Parentheses make the intended grouping explicit.

Connection to “Opposite Signs”: here, intermediate values are best kept in named variables so the formula stays readable and data types remain clear.

💡
NEED HELP? Hints
+

['Translate the verbal condition into one boolean expression.', 'After solving “Opposite Signs”, verify the algorithm on your own small example and on an allowed boundary case. Print only the required result with no extra text.']

ANSWER Solution
+
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
    long long a, b;
    cin >> a >> b;
    cout << ((a * b < 0) ? "YES" : "NO") << '\n';
    return 0;
}