Advertisement
Guest User

Resumen Partidos

a guest
Jun 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. struct Evento {
  6.     //ace, error no forzado, tiro ganador, doble falta, quiebre
  7.     string tipo;
  8.    
  9.     //1 o 2
  10.     int jugador;
  11.    
  12.     Evento(string tipo, int jugador) : tipo(tipo), jugador(jugador) { }
  13. };
  14.  
  15. int indiceTipo(string tipo) {
  16.     if (tipo == "ace")
  17.         return 0;
  18.     if (tipo == "error no forzado")
  19.         return 1;
  20.     else if (tipo == "tiro ganador")
  21.         return 2;
  22.     else if (tipo == "doble falta")
  23.         return 3;
  24.     else if (tipo == "quiebre")
  25.         return 4;
  26.     return -1;
  27.  
  28. }
  29.  
  30. string tipoIndice(int tipo) {
  31.     switch (tipo) {
  32.     case 0:
  33.         return "ace";
  34.     case 1:
  35.         return "error no forzado";
  36.     case 2:
  37.         return "tiro ganador";
  38.     case 3:
  39.         return "doble falta";
  40.     case 4:
  41.         return "quiebre";
  42.     default:
  43.         return "error";
  44.     }
  45. }
  46.  
  47. vector<int> resumen_partido(vector<Evento> eventos, int jugador) {
  48.     vector<int> contador;
  49.     for (int i = 0; i < 5; ++i)
  50.         contador.push_back(0);
  51.     for (Evento& evento : eventos)
  52.         if (evento.jugador == jugador)
  53.             ++contador[indiceTipo(evento.tipo)];
  54.     return contador;
  55. }
  56.  
  57. void mostrarEstadisticas(vector<Evento>& eventos, int jugador) {
  58.     vector<int> resumen = resumen_partido(eventos, jugador);
  59.     int size = resumen.size();
  60.     for (int i = 0; i < size; ++i)
  61.         cout << tipoIndice(i) << ": " << resumen[i] << endl;
  62. }
  63.  
  64. int main(int argc, char *argv[]) {
  65.    
  66.     int count = 0;
  67.     string tipo;
  68.     int jugador;
  69.    
  70.     vector<Evento> eventos;
  71.    
  72.     while (true) {
  73.         cout << "Ingreso de datos del partido" << endl;
  74.         cout << "Datos ingresados: " << count << endl;
  75.         cout << "Finalize la entrada ingresando algún campo vacío" << endl << endl;
  76.         cout << "Tipo de evento: ";
  77.         getline(cin, tipo);
  78.         if (tipo.empty()) break;
  79.         cout << "Jugador: ";
  80.         cin >> jugador;
  81.         cin.ignore();
  82.         if (!jugador) break;
  83.        
  84.         eventos.emplace_back(tipo, jugador);
  85.        
  86.         ++count;
  87.         system("cls");
  88.     }
  89.    
  90.     cout << "Resumen del partido" << endl << endl;
  91.     cout << "Estadisticas del Jugador 1:" << endl;
  92.     mostrarEstadisticas(eventos, 1);
  93.     cout << endl << "Estadisticas del Jugador 2:" << endl;
  94.     mostrarEstadisticas(eventos, 2);
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement