From 6c957dc4e01aee6ce9cae3c8342d04b0fd9ca9c4 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 25 Apr 2017 17:54:10 +0200 Subject: Added new files from PRE OII 2017 --- carte.cpp | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 carte.cpp (limited to 'carte.cpp') diff --git a/carte.cpp b/carte.cpp new file mode 100644 index 0000000..697622a --- /dev/null +++ b/carte.cpp @@ -0,0 +1,105 @@ +/* +INPUT: +18 +12 6 +11 8 +15 8 +15 20 +13 18 +12 23 +11 40 +15 19 +11 25 +13 36 +15 12 +12 18 +17 11 +23 9 +28 22 +35 26 +11 23 +15 12 + +output: +11 96 */ +#include +#include + +using namespace std; + +struct punteggioGiocatori +{ + int idGiocatore; + int punteggio; +} player[100]; + +int ricercaIdGiocatore(int valore, struct punteggioGiocatori* p); + +int main() +{ + ifstream in("input.txt"); + ofstream out("output.txt"); + + int N, i, pPlayer, j = 0, rID, nVal, t[2]; + bool s; + in >> N; + + for(i = 0; i < N; i++) { + player[i].idGiocatore = 0; + player[i].punteggio = 0; + } + + for(i = 0; i < N; i++) { + in >> pPlayer; + rID = ricercaIdGiocatore(pPlayer, player); + if(rID == -1) { + player[j].idGiocatore = pPlayer; + in >> player[j].punteggio; + j++; + } else { + in >> nVal; + player[rID].punteggio += nVal; + } + } + int last = j; + do { + s = false; + for(int k = 0; k < last; k++) + { + if(player[k].punteggio < player[k+1].punteggio) { + t[0] = player[k].idGiocatore; + t[1] = player[k].punteggio; + + player[k].idGiocatore = player[k+1].idGiocatore; + player[k].punteggio = player[k+1].punteggio; + + player[k+1].idGiocatore = t[0]; + player[k+1].punteggio = t[1]; + + s = true; + } + + } + + last--; + } while(s); + + out << player[0].idGiocatore << " " << player[0].punteggio << endl; + + in.close(); + out.close(); +} + +int ricercaIdGiocatore(int valore, struct punteggioGiocatori* p) +{ + int rID = -1; + for(int i = 0; i < 100; i++) + { + if(p[i].idGiocatore == valore) { + rID = i; + break; + } + } + + return rID; +} -- cgit v1.2.3-18-g5258