that_one_nigga_you_k

loolpapoolzA

Jul 18th, 2023
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. typedef struct {
  5.     char nome[30];
  6.     int convidados;
  7.     char comida[30];
  8.     char bebida[30];
  9.     char artista[30];
  10.     int vip;
  11. } pessoa;
  12.  
  13. int main() {
  14.     int chamados;
  15.  
  16.     char bebidas[5][20] = {
  17.         "pitu",
  18.         "agua",
  19.         "suco",
  20.         "monster",
  21.         "cafe"
  22.     };
  23.  
  24.     char artistas[5][20] ={
  25.         "Joao Gomes",
  26.         "Shevchenko e Elloco",
  27.         "Billie Eilish",
  28.         "Pericles",
  29.         "Gustavo Mioto"
  30.     };
  31.  
  32.     char comidas[5][20] = {
  33.         "risoto",
  34.         "pizza",
  35.         "picanha",
  36.         "coxinha",
  37.         "brigadeiro"
  38.     };
  39.  
  40.     printf("Digite o número de pessoas: ");
  41.     scanf("%d", &chamados);
  42.  
  43.     pessoa lista[chamados];
  44.     int vip[chamados];
  45.  
  46.     for (int i = 0; i < chamados; i++) {
  47.         strcpy(lista[i].nome, "NULL");
  48.         strcpy(lista[i].comida, "NULL");
  49.         strcpy(lista[i].bebida, "NULL");
  50.         strcpy(lista[i].artista, "NULL");
  51.         lista[i].convidados = 0;
  52.         lista[i].vip = 0;
  53.         vip[i] = 0;
  54.     }
  55.  
  56.     for (int i = 0; i < chamados; i++) {
  57.         getchar();
  58.         printf("\nDigite o nome, número de convites, comida, bebida e artista: ");
  59.         scanf("%s %d %s %s %[^\n]", lista[i].nome, &lista[i].convidados, lista[i].comida, lista[i].bebida, lista[i].artista);
  60.     }
  61.  
  62.     int pitu, agua, cafe, suco, monster = 0;
  63.     int coxinha, brigadeiro, picanha, risoto, pizza = 0;
  64.     int bil, gus, per, shev, jao = 0;
  65.  
  66.     int va[5];
  67.     int vb[5];
  68.     int vc[5];
  69.  
  70.     for (int i = 0; i < 5; i++) {
  71.         va[i] = 0;
  72.         vb[i] = 0;
  73.         vc[i] = 0;
  74.     }
  75.  
  76.     for (int i = 0; i < chamados; i++) {
  77.         if (strcmp(lista[i].bebida, "pitu") == 0) {
  78.             pitu++;
  79.             vb[0]++;
  80.         }
  81.         if (strcmp(lista[i].bebida, "agua") == 0) {
  82.             agua++;
  83.             vb[1]++;
  84.         }
  85.         if (strcmp(lista[i].bebida, "suco") == 0) {
  86.             suco++;
  87.             vb[2]++;
  88.         }
  89.         if (strcmp(lista[i].bebida, "monster") == 0) {
  90.             monster++;
  91.             vb[3]++;
  92.         }
  93.         if (strcmp(lista[i].bebida, "cafe") == 0) {
  94.             cafe++;
  95.             vb[4]++;
  96.         }
  97.         if (strcmp(lista[i].comida, "risoto") == 0) {
  98.             risoto++;
  99.             vc[0]++;
  100.         }
  101.         if (strcmp(lista[i].comida, "pizza") == 0) {
  102.             pizza++;
  103.             vc[1]++;
  104.         }
  105.         if (strcmp(lista[i].comida, "picanha") == 0) {
  106.             picanha++;
  107.             vc[2]++;
  108.         }
  109.         if (strcmp(lista[i].comida, "coxinha") == 0) {
  110.             coxinha++;
  111.             vc[3]++;
  112.         }
  113.         if (strcmp(lista[i].comida, "brigadeiro") == 0) {
  114.             brigadeiro++;
  115.             vc[4]++;
  116.         }
  117.         if (strcmp(lista[i].artista, "Joao Gomes") == 0) {
  118.             jao++;
  119.             va[0]++;
  120.         }
  121.         if (strcmp(lista[i].artista, "Shevchenko e Elloco") == 0) {
  122.             shev++;
  123.             va[1]++;
  124.         }
  125.         if (strcmp(lista[i].artista, "Billie Eilish") == 0) {
  126.             bil++;
  127.             va[2]++;
  128.         }
  129.         if (strcmp(lista[i].artista, "Pericles") == 0) {
  130.             per++;
  131.             va[3]++;
  132.         }
  133.         if (strcmp(lista[i].artista, "Gustavo Mioto") == 0) {
  134.             gus++;
  135.             va[4]++;
  136.         }
  137.     }
  138.  
  139.     int art = 0, com = 0, beb = 0;
  140.     int vena, venb, venc;
  141.  
  142.     for (int i = 0; i < 5; i++) {
  143.         if (va[i] > art) {
  144.             art = va[i];
  145.             vena = i;
  146.         }
  147.         if (vb[i] > beb) {
  148.             beb = vb[i];
  149.             venb = i;
  150.         }
  151.         if (vc[i] > com) {
  152.             com = vc[i];
  153.             venc = i;
  154.         }
  155.     }
  156.  
  157.     char artistaMaisPreferido[30];
  158.     char bebidaMaisPreferida[30];
  159.     char comidaMaisPreferida[30];
  160.  
  161.     strcpy(artistaMaisPreferido, artistas[vena]);
  162.     strcpy(bebidaMaisPreferida, bebidas[venb]);
  163.     strcpy(comidaMaisPreferida, comidas[venc]);
  164.  
  165.     int numCheg = 1000000;
  166.     int cheg[chamados];
  167.  
  168.     for (int i = 0; i < chamados; i++) {
  169.         cheg[i] = lista[i].convidados;
  170.         if (cheg[i] < numCheg) {
  171.             numCheg = cheg[i];
  172.         }
  173.     }
  174.  
  175.     int maisVotado = 0;
  176.     int vipList[chamados];
  177.     int vipCount = 0;
  178.  
  179.     for (int i = 0; i < chamados; i++) {
  180.         vip[i] = 0;
  181.  
  182.         if (strcmp(lista[i].bebida, bebidaMaisPreferida) == 0) {
  183.             vip[i]++;
  184.         }
  185.         if (strcmp(lista[i].artista, artistaMaisPreferido) == 0) {
  186.             vip[i]++;
  187.         }
  188.         if (strcmp(lista[i].comida, comidaMaisPreferida) == 0) {
  189.             vip[i]++;
  190.         }
  191.         if (lista[i].convidados == numCheg) {
  192.             vip[i]++;
  193.         }
  194.  
  195.         if (vip[i] > maisVotado) {
  196.             maisVotado = vip[i];
  197.             vipCount = 1;
  198.             vipList[0] = i;
  199.             lista[i].vip = 1;
  200.         }
  201.         else if (vip[i] == maisVotado) {
  202.             vipList[vipCount] = i;
  203.             vipCount++;
  204.             lista[i].vip = 1;
  205.         }
  206.     }
  207.  
  208.     int numVip = 0;
  209.     int ind[chamados];
  210.     printf("Artista mais preferido: %s\n", artistaMaisPreferido);
  211.     printf("Bebida mais preferida: %s\n", bebidaMaisPreferida);
  212.     printf("Comida mais preferida: %s\n", comidaMaisPreferida);
  213.     printf("Menor número de convidados que alguém quer trazer: %d\n", numCheg);
  214.  
  215.     printf("Lista VIP:");
  216.     for (int i = 0; i < chamados; i++) {
  217.         if (lista[i].vip == 1) {
  218.             printf("\n%s", lista[i].nome);
  219.             numVip++;
  220.             ind[numVip-1] = i;
  221.         }
  222.     }
  223.     char listaVip[numVip][50];
  224.  
  225.     for (int i = 0; i < numVip; i++) {
  226.         strcpy(listaVip[i], lista[ind[i]].nome);
  227.     }
  228.  
  229.     char aux[50];
  230.  
  231.     for (int i = 0; i < numVip; i++) {
  232.         for (int j = i + 1; j < numVip; j++) {
  233.             if (strcmp(listaVip[i], listaVip[j]) > 0) {
  234.                 strcpy(aux, listaVip[i]);
  235.                 strcpy(listaVip[i], listaVip[j]);
  236.                 strcpy(listaVip[j], aux);
  237.             }
  238.         }
  239.     }
  240.  
  241.     printf("\n\nEm ordem alfabética:");
  242.     for (int i = 0; i < numVip; i++) {
  243.         printf("\n%s", listaVip[i]);
  244.     }
  245.  
  246.     return 0;
  247. }
  248.  
Add Comment
Please, Sign In to add comment