C++20 sections · 1024 units
Open in Course

Nearly Lucky - Algorithm

Breaking down the solution

Here's your approach:

1.1. Read the number as a long integer.

2.2. Initialize a counter to 0.

3.3. Loop while the number is greater than 0.

4.4. Get the last digit using modulo 10.

5.5. If the digit is 4 or 7, increment the counter.

6.6. Divide the number by 10 to remove the last digit.

7.7. After the loop, check if the counter is a lucky number by verifying all its digits are 4 or 7.

8.8. Output YES if the counter is lucky, NO otherwise. You need to handle the special case where the counter is 0 (no lucky digits found), which is not a lucky number.