Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- struct Evento {
- //ace, error no forzado, tiro ganador, doble falta, quiebre
- string tipo;
- //1 o 2
- int jugador;
- Evento(string tipo, int jugador) : tipo(tipo), jugador(jugador) { }
- };
- int indiceTipo(string tipo) {
- if (tipo == "ace")
- return 0;
- if (tipo == "error no forzado")
- return 1;
- else if (tipo == "tiro ganador")
- return 2;
- else if (tipo == "doble falta")
- return 3;
- else if (tipo == "quiebre")
- return 4;
- return -1;
- }
- string tipoIndice(int tipo) {
- switch (tipo) {
- case 0:
- return "ace";
- case 1:
- return "error no forzado";
- case 2:
- return "tiro ganador";
- case 3:
- return "doble falta";
- case 4:
- return "quiebre";
- default:
- return "error";
- }
- }
- vector<int> resumen_partido(vector<Evento> eventos, int jugador) {
- vector<int> contador;
- for (int i = 0; i < 5; ++i)
- contador.push_back(0);
- for (Evento& evento : eventos)
- if (evento.jugador == jugador)
- ++contador[indiceTipo(evento.tipo)];
- return contador;
- }
- void mostrarEstadisticas(vector<Evento>& eventos, int jugador) {
- vector<int> resumen = resumen_partido(eventos, jugador);
- int size = resumen.size();
- for (int i = 0; i < size; ++i)
- cout << tipoIndice(i) << ": " << resumen[i] << endl;
- }
- int main(int argc, char *argv[]) {
- int count = 0;
- string tipo;
- int jugador;
- vector<Evento> eventos;
- while (true) {
- cout << "Ingreso de datos del partido" << endl;
- cout << "Datos ingresados: " << count << endl;
- cout << "Finalize la entrada ingresando algún campo vacío" << endl << endl;
- cout << "Tipo de evento: ";
- getline(cin, tipo);
- if (tipo.empty()) break;
- cout << "Jugador: ";
- cin >> jugador;
- cin.ignore();
- if (!jugador) break;
- eventos.emplace_back(tipo, jugador);
- ++count;
- system("cls");
- }
- cout << "Resumen del partido" << endl << endl;
- cout << "Estadisticas del Jugador 1:" << endl;
- mostrarEstadisticas(eventos, 1);
- cout << endl << "Estadisticas del Jugador 2:" << endl;
- mostrarEstadisticas(eventos, 2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement