fork(5) download
  1. #include <iostream>
  2. #include <functional>
  3. using namespace std;
  4.  
  5. typedef std::function<int()> fi_t;
  6.  
  7. int main() {
  8. fi_t nil = []()->int {return -1;};
  9.  
  10. auto cons = [](int a, const fi_t& s) -> fi_t {
  11. int p=0; return [=]() mutable -> int {
  12. if (p) return s(); else {p=1; return a;}}; };
  13.  
  14. auto show = [](const fi_t& f, auto& la) -> int {
  15. int e=f(); if (e>0) {cout<<e<<'\t'; return la(f, la);}
  16. else {cout<<'\n'; return 0;}};
  17.  
  18. auto num2list = [=](int n, const auto& la) -> fi_t {
  19. return n ? cons(n%10, la(n/10, la)) : nil;};
  20.  
  21. int n; cin>>n; fi_t s = num2list(n, num2list); show(s, show);
  22. return 0;
  23. }
Success #stdin #stdout 0s 3468KB
stdin
37156
stdout
6	5	1	7	3