Advertisement
Hamoudi30

Untitled

Jul 31st, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll  long long
  4. #define SZ(v)   (int((v).size()))
  5. #define pb  push_back
  6. vector<ll> lucky;
  7. void pre_calc (ll num) {
  8.     if (num > 1e10)
  9.         return;
  10.     lucky.pb(num);
  11.     pre_calc((num * 10) + 7);
  12.     pre_calc((num * 10) + 4);
  13. }
  14. void run () {
  15.     int n;
  16.     cin >> n;
  17.     pre_calc(0);
  18.     sort(lucky.begin(), lucky.end());
  19.     for (int i = 0; i < SZ(lucky); ++i) {
  20.         if (lucky[i] >= n) {
  21.             int four, seven;
  22.             four = seven = 0;
  23.             ll cur = lucky[i];
  24.             while (cur) {
  25.                 if (cur % 10 == 4)
  26.                     four++;
  27.                 else
  28.                     seven++;
  29.                 cur /= 10;
  30.             }
  31.             if (four == seven) {
  32.                 cout << lucky[i] << '\n';
  33.                 return;
  34.             }
  35.         }
  36.     }
  37. }
  38. int main () {
  39.     ios_base::sync_with_stdio(false);
  40.     cin.tie(nullptr);
  41.     cout.tie(nullptr);
  42. //    freopen("/home/hamoudi/clion/hello.in", "rt", stdin);
  43.     int tt;
  44.     tt = 1;
  45. //    cin >> tt;
  46.     while (tt--)
  47.         run();
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement