fork(1) download
  1. #include<iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int count=0,cache[50];
  6.  
  7. int f(int n)
  8. {
  9. if(n==2) count++;
  10. if(n==0 || n==1) return n;
  11. else if(cache[n]!=-1) return cache[n];
  12. else cache[n]= f(n-1)+f(n-2);
  13. return cache[n];
  14. }
  15.  
  16. int main()
  17. {
  18. std::cout << f(5);
  19. return 0;
  20. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int f(int)’:
prog.cpp:9: error: reference to ‘count’ is ambiguous
prog.cpp:5: error: candidates are: int count
/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_algo.h:3987: error:                 template<class _IIter, class _Tp> typename std::iterator_traits::difference_type std::count(_IIter, _IIter, const _Tp&)
prog.cpp:9: error: reference to ‘count’ is ambiguous
prog.cpp:5: error: candidates are: int count
/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_algo.h:3987: error:                 template<class _IIter, class _Tp> typename std::iterator_traits::difference_type std::count(_IIter, _IIter, const _Tp&)
stdout
Standard output is empty