Advertisement
LEGEND2004

K - Nearly Lucky Number

Jun 29th, 2023
979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool lucky(int n){
  5.     if(!n)
  6.         return false;
  7.     while(n){
  8.         int d = n % 10;
  9.         if((d != 4) && (d != 7))
  10.             return false;
  11.         n /= 10;
  12.     }
  13.     return true;
  14. }
  15.  
  16. signed main()
  17. {
  18.     string s;
  19.     cin >> s;
  20.     int cnt = 0;
  21.     for(int i = 0; i < s.size(); i++){
  22.         if((s[i] == '4') || (s[i] == '7'))
  23.             cnt++;
  24.     }
  25.     cout << ((lucky(cnt)) ? "YES" : "NO") << endl;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement