Advertisement
nRikee

Emparellar en C++

Jul 9th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int numJugadors; // ¿Cuántos jugadores?
  11.     string *jugadors = NULL; // Futura array dinámica con 'numJugadors' elementos
  12.     string aux;
  13.  
  14.     /** ¿Cuántos vais a ser? */
  15.     cout << "Numero de jugadores ";
  16.     cin >> numJugadors;
  17.     cout << endl;
  18.  
  19.     jugadors = new string[numJugadors]; // Creación del array, sitios reservados
  20.  
  21.     /** ¿Vuestros nombres? */
  22.     for(int a=0; a<numJugadors; a++){
  23.         cout << "Jugador " << a+1 << ": ";
  24.         cin >> aux;
  25.         jugadors[a] = aux;
  26.     }
  27.     cout << endl;
  28.  
  29.     /** Empieza lo random */
  30.     srand(time(0));
  31.     int historial[numJugadors];
  32.     int rdm, numHist=0;
  33.     bool repe = false;
  34.  
  35.     for(int a=0; a<numJugadors; a++){
  36.         do{
  37.             repe = false;
  38.             rdm = rand()%numJugadors;
  39.             for(int b=0; b<numHist; b++) if(historial[b] == rdm) repe = true;
  40.         } while( repe == true );
  41.  
  42.         cout << jugadors[rdm] << endl;
  43.         if(numHist%2==1) cout << endl;
  44.         historial[numHist] = rdm;
  45.         numHist++;
  46.     }
  47.  
  48.     /** ¿No habría que eliminarlos? Si lo hago se cierra el programa. */
  49.     //delete jugadors[];
  50.     //delete jugadors;
  51.     //delete jugAux;
  52.  
  53.     getch(); // Pausa hasta presionar una tecla
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement