Advertisement
nRikee

emparellar

Jun 23rd, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #define TRUE 1
  6. #define FALSE 0
  7.  
  8. int main()
  9. {
  10.     int n = 0; // Nímero de jugadors
  11.     int m; // Màxim de jugadors
  12.     srand(time(NULL));
  13.  
  14.     /** Obtindre els noms */
  15.     printf("Numero de jugadors? ");
  16.     scanf("%d",&m);
  17.     char jugadors[m][20];
  18.     for(int a=0; a<m; a++){
  19.         printf("Jugador %d: ",a);
  20.         scanf("%s",&jugadors[a]);
  21.     }
  22.  
  23.     int historial[m];
  24.     int repetit = FALSE;
  25.     int x;
  26.  
  27.     for(int a=0; a<m; a++){
  28.         do{
  29.             x = rand() % m;
  30.             repetit = FALSE;
  31.             for(int b=0; b<a; b++){
  32.                 if(historial[b]==x) repetit = TRUE;
  33.             }
  34.             if(a==0) repetit = FALSE;
  35.  
  36.         } while ( repetit==TRUE );
  37.         historial[a] = x;
  38.         if(a%2==0) printf("\n");
  39.         printf("%s\n",jugadors[x]);
  40.     }
  41.  
  42.     system("sleep 10");
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement