Can anyone help ? I can't understand this recursion function

Revision en1, by Spam_498002, 2021-10-15 16:23:17

include<bits/stdc++.h>

using namespace std; typedef long long ll; vector a; ll N; void dfs(ll now, int four, int seven) { if (now > 100000000000ll) return; if (four == seven) {a.push_back(now);} //cout<<now<<endl; dfs(now * 10 + 4, four + 1, seven); dfs(now * 10 + 7, four, seven + 1); }

int main() { cin >> N; a.clear(); dfs(0, 0, 0); sort(a.begin(), a.end()); int u = 0; for (; a[u] < N; ++u); cout << a[u] << endl;

return 0;

}

Tags help, blog, problem solving

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English Spam_498002 2021-10-15 16:27:14 469
en3 English Spam_498002 2021-10-15 16:25:53 20 Tiny change: 'em/B\n\n\n\n==================#include<b' -> 'em/B\n\n\n#include<b'
en2 English Spam_498002 2021-10-15 16:24:55 70 (published)
en1 English Spam_498002 2021-10-15 16:23:17 540 Initial revision (saved to drafts)