fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. vector<ll> a;
  5. ll N;
  6. void dfs(ll now, int four, int seven)
  7. {
  8. if (now > 100000000000ll) return;
  9. if (four == seven) {a.push_back(now);}
  10. //cout<<now<<endl;
  11. dfs(now * 10 + 4, four + 1, seven);
  12. dfs(now * 10 + 7, four, seven + 1);
  13. }
  14.  
  15. int main()
  16. {
  17. cin >> N;
  18. a.clear();
  19. dfs(0, 0, 0);
  20. sort(a.begin(), a.end());
  21. int u = 0;
  22. for (; a[u] < N; ++u);
  23. cout << a[u] << endl;
  24.  
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0.01s 5532KB
stdin
Standard input is empty
stdout
0