PROBLEM 68
Medium

Contains Digit Seven

Programming Basics · C++

</>
STATUS Not solved

TASK

Problem

#68

In “Contains Digit Seven”, given the required decimal number, print YES if a three-digit number contains digit 7.

EXAMPLE

Example

Input
123
Output
NO

LIMITS

Constraints

The number has exactly the number of decimal digits stated in the task and is non-negative.
📖
LEARN Theory for this problem
+

Repeated division by powers of 10 and `% 10` isolate decimal digits without converting the number to a string.

Connection to “Contains Digit Seven”: here, integer `/` and `%` provide the quotient and remainder, which is useful for digit extraction and cyclic arithmetic.

💡
NEED HELP? Hints
+

['Extract the digits first, then combine or compare them.', 'After solving “Contains Digit Seven”, 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 <algorithm>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a = n / 100, b = (n / 10) % 10, c = n % 10;
    cout << (a == 7 || b == 7 || c == 7 ? "YES" : "NO") << '\n';
    return 0;
}