diff options
author | Santo Cariotti <sancn@live.com> | 2017-04-25 17:54:10 +0200 |
---|---|---|
committer | Santo Cariotti <sancn@live.com> | 2017-04-25 17:54:10 +0200 |
commit | 6c957dc4e01aee6ce9cae3c8342d04b0fd9ca9c4 (patch) | |
tree | 22538a4f2169cf574f96d65d48887e279d8732b2 /bicicletta.c++ | |
parent | bca44eed99ddc009f6fc172f2654ba7ae6088598 (diff) |
Added new files from PRE OII 2017
Diffstat (limited to 'bicicletta.c++')
-rw-r--r-- | bicicletta.c++ | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/bicicletta.c++ b/bicicletta.c++ new file mode 100644 index 0000000..bb42031 --- /dev/null +++ b/bicicletta.c++ @@ -0,0 +1,62 @@ +/* INPUT: +3 4 +2 +3 +1 +1 3 +1 2 +3 2 +3 1 + +OUTPUT: +3 +*/ + +#include <iostream> +#include <fstream> + +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; +} |