Advertisement
Guest User

inhai

a guest
Oct 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5.  
  6. struct auxiliar
  7. {
  8.   int aux_hab[50];
  9. };
  10.  
  11. struct cartas
  12. {
  13.   char nome[40];
  14.   char jogada[40];
  15.   int hab[50];
  16.   int qtde_hab;
  17. };
  18.  
  19. void printar(struct cartas pnt[], struct auxiliar hab[], int qtde, char primeiro[], int c1, int c2)
  20. {
  21.   //printf("%s\t%s\n", pnt[4].nome, pnt[1].jogada);
  22.   printf("%d %d\n", c1, c2);
  23.   if(c2 == qtde)
  24.   {
  25.     printf("retorno\n");
  26.     return;
  27.   }
  28.   else
  29.   {
  30.     if(c2 == 0)
  31.     {
  32.       if(strcmp(primeiro, pnt[c1].nome) == 0)
  33.       {
  34.         //printf("print %d %s\n", c2, pnt[c1].nome);
  35.         c2 += 1;
  36.         c1 = 0;
  37.         printar(pnt, hab, qtde, primeiro, c1, c2);
  38.       }
  39.       else
  40.       {
  41.         printar(pnt, hab, qtde, primeiro, c1+1, c2);
  42.       }
  43.     }
  44.     else
  45.     {
  46.       if(strcmp(primeiro, pnt[c1].nome) == 0)
  47.       {
  48.         printar(pnt, hab, qtde, primeiro, 0, c2+1);
  49.       }
  50.       else if(strcmp(pnt[c2].jogada, pnt[c1].nome) == 0)
  51.       {
  52.         //printf("print %d %s\n", c2, pnt[c1].nome);
  53.         c2 += 1;
  54.         c1 = 0;
  55.         printar(pnt, hab, qtde, primeiro, c1, c2);
  56.       }
  57.     }
  58.     printar(pnt, hab, qtde, primeiro, c1+1, c2);
  59.   }
  60. }
  61.  
  62. void ordenar(struct cartas ordem[], struct auxiliar g[], int qtde, char aux[], int count)
  63. {
  64.   int i, j, k;
  65.   if(count == qtde)
  66.   {
  67.     return;
  68.   }
  69.   else
  70.   {
  71.     for(i = 0; i < qtde; i++)
  72.     {
  73.       for(j = 0; j < qtde-1; j++)
  74.       {
  75.         if(strcmp(ordem[j].nome, ordem[j+1].nome) > 0)
  76.         {
  77.           strcpy(aux, ordem[j+1].nome);
  78.           strcpy(ordem[j+1].nome, ordem[j].nome);
  79.           strcpy(ordem[j].nome, aux);
  80.           for(k = 0; k < 50; k++)
  81.           {
  82.             g[j].aux_hab[k] = ordem[j+1].hab[k];
  83.             ordem[j+1].hab[k] = ordem[j].hab[k];
  84.             ordem[j].hab[k] = g[j].aux_hab[k];
  85.           }
  86.         }
  87.       }
  88.     }
  89.     // printf("%s\n", ordem[count].jogada);
  90.     ordenar(ordem, g, qtde, aux, count+1);
  91.   }
  92. }
  93.  
  94. void ler_struct(struct cartas ler[], int qtde, int count)
  95. {
  96.   int i;
  97.  
  98.   if(count == qtde)
  99.   {
  100.     return;
  101.   }
  102.   else
  103.   {
  104.     scanf(" %[^\n]s", ler[count].nome);
  105.     scanf("%d", &ler[count].qtde_hab);
  106.  
  107.     for(i = 0; i < ler[count].qtde_hab; i++)
  108.     {
  109.       scanf("%d", &ler[count].hab[i]);
  110.     }
  111.     scanf(" %[^\n]s", ler[count].jogada);
  112.   }
  113.   ler_struct(ler, qtde, count+1);
  114. }
  115.  
  116. int main()
  117. {
  118.   int qtde;
  119.   scanf("%d", &qtde);
  120.   struct cartas c[qtde];
  121.   struct auxiliar a[qtde];
  122.   ler_struct(c, qtde, 0);
  123.   char aux[40];
  124.   ordenar(c, a, qtde, aux, 0);
  125.   char inicial[40];
  126.   scanf(" %[^\n]s", inicial);
  127.   printar(c, a, qtde, inicial, 0, 0);
  128.  
  129.   return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement