From 483d63fa7249ad8d6020680c48c3cf6df35010b3 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Wed, 26 Apr 2017 16:37:39 +0200 Subject: Moved all C++ files into CPP folder --- cpp/bicicletta.c++ | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 cpp/bicicletta.c++ (limited to 'cpp/bicicletta.c++') diff --git a/cpp/bicicletta.c++ b/cpp/bicicletta.c++ new file mode 100644 index 0000000..bb42031 --- /dev/null +++ b/cpp/bicicletta.c++ @@ -0,0 +1,62 @@ +/* INPUT: +3 4 +2 +3 +1 +1 3 +1 2 +3 2 +3 1 + +OUTPUT: +3 +*/ + +#include +#include + +using namespace std; + +int main(void) +{ + ifstream in; + ofstream out; + in.open("input.txt"); + out.open("output.txt"); + + int numBici, sorpassi, i, x, j, y, m[2]; + in >> numBici; + in >> sorpassi; + + int* posBici = new int[numBici]; + + // posizioni di base + for(i = 0; i < numBici; i++) + in >> posBici[i]; + + // sorpassi + for(i = 0; i < sorpassi; i++) + { + in >> x; + in >> y; + + for(j = 0; j < numBici; j++) + { + if(posBici[j] == x) m[0] = j; //indice valore che sorpassa + + if(posBici[j] == y) m[1] = j; //indice valore che viene sorpassato + } + + posBici[m[0]] = y; + posBici[m[1]] = x; + } + + out << posBici[0]; + + delete[] posBici; + + in.close(); + out.close(); + + return 0; +} -- cgit v1.2.3-18-g5258