diff options
author | Santo Cariotti <sancn@live.com> | 2017-04-12 20:07:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-12 20:07:35 +0200 |
commit | af1befc64570360d4f1e6f85b94d2546612a8dd0 (patch) | |
tree | 1530a8bdfb06a8d2e2adfb46cd9d32ff1b8fb9e2 | |
parent | 785a4d0a00df64be60a4c3e81a11ea9f9ec32b4f (diff) |
OII 20
-rw-r--r-- | lswf.cpp | 53 | ||||
-rw-r--r-- | scommesse.cpp | 73 |
2 files changed, 126 insertions, 0 deletions
diff --git a/lswf.cpp b/lswf.cpp new file mode 100644 index 0000000..573509b --- /dev/null +++ b/lswf.cpp @@ -0,0 +1,53 @@ +/* INPUT: + * 19 + * + * OUTPUT: + * 1000101 + */ +#include <iostream> +#include <fstream> +#define MAXG 1000 + +using namespace std; + +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() +{ + ifstream in("input.txt"); + ofstream out("output.txt"); + + int N, i; + in >> N; + int caracts[MAXG], somma = 0, potSomma; + int lastc = fibonacci(caracts, N); + int* seq = new int[lastc]; + + //for(i = 0; i < lastc; i++) cout << caracts[i] << ' '; cout << endl; + + seq[0] = 1; + for(i = lastc; i > 0; i--) { + potSomma = somma + caracts[i]; + if(potSomma < N) { + somma = potSomma; + seq[i] = 1; + } else seq[i] = 0; + } + for(i = 0; i < lastc; i++) out << seq[i]; + delete[] seq; + in.close(); + out.close(); + return 0; +} diff --git a/scommesse.cpp b/scommesse.cpp new file mode 100644 index 0000000..0ba6e3c --- /dev/null +++ b/scommesse.cpp @@ -0,0 +1,73 @@ +/* INPUT: + * 11 + * 1 0 2 6 4 5 3 9 8 10 7 + * + * OUTPUT: + * 2 + * 8 2 + */ +#include <iostream> +#include <iostream> +#include <fstream> +#include <vector> + +using namespace std; + +vector<int> carteOut; + +void cOutPresente(vector<int>& kr, int x) +{ + bool s = false; + for(unsigned i = 0; i < kr.size(); i++) + if(kr[i] == x) s = true; + + if(!s) + kr.push_back(x); +} + +void fCarte(int carte[], int N, int s) +{ + int i; + vector<int> c; + vector<int>::iterator it; + vector<int>::iterator start; + for(i = 0; i < N; i++) c.push_back(carte[i]); + + while(c.size() > 1) { + //for(it = c.begin(); it != c.end(); it++) cout << *it << ' '; cout << endl; + int tot = c.size(); + for(i = s; i < tot-1; i++) { + if(!(((c[i] + c[i+1]) % 2) == 0)) { + start = c.begin()+i; + c.erase(start, start+2); + break; + } + } + + s = 0; + } + cOutPresente(carteOut, c[0]); +} + +int main() +{ + ifstream in("input.txt"); + ofstream out("output.txt"); + int N, i; + in >> N; + + int* carte = new int[N]; + + for(i = 0; i < N; i++) in >> carte[i]; + + for(int i = 0; i < N; i++) { + fCarte(carte, N, i); + } + out << carteOut.size() << endl; + for(vector<int>::iterator ite = carteOut.begin(); ite != carteOut.end(); ite++) out << *ite << ' '; + + delete[] carte; + out.close(); + in.close(); + return 0; +} |