Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <conio.h>
- using namespace std;
- int main()
- {
- int numJugadors; // ¿Cuántos jugadores?
- string *jugadors = NULL; // Futura array dinámica con 'numJugadors' elementos
- string aux;
- /** ¿Cuántos vais a ser? */
- cout << "Numero de jugadores ";
- cin >> numJugadors;
- cout << endl;
- jugadors = new string[numJugadors]; // Creación del array, sitios reservados
- /** ¿Vuestros nombres? */
- for(int a=0; a<numJugadors; a++){
- cout << "Jugador " << a+1 << ": ";
- cin >> aux;
- jugadors[a] = aux;
- }
- cout << endl;
- /** Empieza lo random */
- srand(time(0));
- int historial[numJugadors];
- int rdm, numHist=0;
- bool repe = false;
- for(int a=0; a<numJugadors; a++){
- do{
- repe = false;
- rdm = rand()%numJugadors;
- for(int b=0; b<numHist; b++) if(historial[b] == rdm) repe = true;
- } while( repe == true );
- cout << jugadors[rdm] << endl;
- if(numHist%2==1) cout << endl;
- historial[numHist] = rdm;
- numHist++;
- }
- /** ¿No habría que eliminarlos? Si lo hago se cierra el programa. */
- //delete jugadors[];
- //delete jugadors;
- //delete jugAux;
- getch(); // Pausa hasta presionar una tecla
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement