diff options
author | Santo Cariotti <sancn@live.com> | 2017-05-18 17:08:49 +0200 |
---|---|---|
committer | Santo Cariotti <sancn@live.com> | 2017-05-18 17:08:49 +0200 |
commit | f17ed4a016316a065375bce35c5588ae76a25948 (patch) | |
tree | 8211c00125b26424b1dc1503e815b921d1d68575 /cpp | |
parent | 5c1ff51bc5a99115ae6c8a62a0168da31cc29f11 (diff) |
same file without lambda function
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/lswf.cpp | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/cpp/lswf.cpp b/cpp/lswf.cpp index 79f46c7..dcf1b13 100644 --- a/cpp/lswf.cpp +++ b/cpp/lswf.cpp @@ -9,6 +9,20 @@ #include <list> #define MAXG 1000001 +int fibonacci(int* fib, int N) +{ + fib[0] = 1; fib[1] = 1; + int lst; + + for(int i = 2; i < N; i++) { + fib[i] = fib[i-1] + fib[i-2]; + lst = i; + if(fib[i] > N) break; + } + + return lst; +} + int main() { std::ifstream in("input.txt"); @@ -21,24 +35,8 @@ int main() int caracts[MAXG], somma = 0, potSomma; int lastc; - auto fibonacci = [&caracts] (int N) { - caracts[0] = 1; caracts[1] = 1; - - int lst; - - for(int i = 2; i < N; i++) { - caracts[i] = caracts[i-1] + caracts[i-2]; - lst = i; - - if(caracts[i] > N) - break; - } - - return lst; - }; - if(N > 4) - lastc = fibonacci(N); + lastc = fibonacci(caracts, N); else { caracts[0] = 1; for(i = 1; i < 4; i++) |