From 17a67a4cd53939413296ce7ce7ac35a96b7aff96 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sat, 27 May 2017 15:39:44 +0200 Subject: * --- lswf.cpp | 73 ---------------------------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 lswf.cpp (limited to 'lswf.cpp') diff --git a/lswf.cpp b/lswf.cpp deleted file mode 100644 index dcf1b13..0000000 --- a/lswf.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* INPUT: - * 19 - * - * OUTPUT: - * 1000101 - */ -#include -#include -#include -#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"); - std::ofstream out("output.txt"); - std::list seq; - std::list::iterator j; - - int N, i; - in >> N; - int caracts[MAXG], somma = 0, potSomma; - int lastc; - - if(N > 4) - lastc = fibonacci(caracts, N); - else { - caracts[0] = 1; - for(i = 1; i < 4; i++) - caracts[i] = i; - - switch (N) { - case 1: - lastc = 1; - break; - case 2: - lastc = 2; - break; - case 3: - lastc = 3; - break; - default: - lastc = 4; - } - } - - for(i = lastc; i > 0; i--) { - potSomma = somma + caracts[i]; - if(potSomma < N) { - somma = potSomma; - seq.push_front(1); - } else seq.push_front(0); - } - seq.push_front(1); - for(j = seq.begin(); j != seq.end(); j++) out << *j; - - in.close(); - out.close(); - return 0; -} -- cgit v1.2.3-18-g5258