Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- typedef struct {
- char nome[30];
- int convidados;
- char comida[30];
- char bebida[30];
- char artista[30];
- int vip;
- } pessoa;
- int main() {
- int chamados;
- char bebidas[5][20] = {
- "pitu",
- "agua",
- "suco",
- "monster",
- "cafe"
- };
- char artistas[5][20] ={
- "Joao Gomes",
- "Shevchenko e Elloco",
- "Billie Eilish",
- "Pericles",
- "Gustavo Mioto"
- };
- char comidas[5][20] = {
- "risoto",
- "pizza",
- "picanha",
- "coxinha",
- "brigadeiro"
- };
- printf("Digite o número de pessoas: ");
- scanf("%d", &chamados);
- pessoa lista[chamados];
- int vip[chamados];
- for (int i = 0; i < chamados; i++) {
- strcpy(lista[i].nome, "NULL");
- strcpy(lista[i].comida, "NULL");
- strcpy(lista[i].bebida, "NULL");
- strcpy(lista[i].artista, "NULL");
- lista[i].convidados = 0;
- lista[i].vip = 0;
- vip[i] = 0;
- }
- for (int i = 0; i < chamados; i++) {
- getchar();
- printf("\nDigite o nome, número de convites, comida, bebida e artista: ");
- scanf("%s %d %s %s %[^\n]", lista[i].nome, &lista[i].convidados, lista[i].comida, lista[i].bebida, lista[i].artista);
- }
- int pitu, agua, cafe, suco, monster = 0;
- int coxinha, brigadeiro, picanha, risoto, pizza = 0;
- int bil, gus, per, shev, jao = 0;
- int va[5];
- int vb[5];
- int vc[5];
- for (int i = 0; i < 5; i++) {
- va[i] = 0;
- vb[i] = 0;
- vc[i] = 0;
- }
- for (int i = 0; i < chamados; i++) {
- if (strcmp(lista[i].bebida, "pitu") == 0) {
- pitu++;
- vb[0]++;
- }
- if (strcmp(lista[i].bebida, "agua") == 0) {
- agua++;
- vb[1]++;
- }
- if (strcmp(lista[i].bebida, "suco") == 0) {
- suco++;
- vb[2]++;
- }
- if (strcmp(lista[i].bebida, "monster") == 0) {
- monster++;
- vb[3]++;
- }
- if (strcmp(lista[i].bebida, "cafe") == 0) {
- cafe++;
- vb[4]++;
- }
- if (strcmp(lista[i].comida, "risoto") == 0) {
- risoto++;
- vc[0]++;
- }
- if (strcmp(lista[i].comida, "pizza") == 0) {
- pizza++;
- vc[1]++;
- }
- if (strcmp(lista[i].comida, "picanha") == 0) {
- picanha++;
- vc[2]++;
- }
- if (strcmp(lista[i].comida, "coxinha") == 0) {
- coxinha++;
- vc[3]++;
- }
- if (strcmp(lista[i].comida, "brigadeiro") == 0) {
- brigadeiro++;
- vc[4]++;
- }
- if (strcmp(lista[i].artista, "Joao Gomes") == 0) {
- jao++;
- va[0]++;
- }
- if (strcmp(lista[i].artista, "Shevchenko e Elloco") == 0) {
- shev++;
- va[1]++;
- }
- if (strcmp(lista[i].artista, "Billie Eilish") == 0) {
- bil++;
- va[2]++;
- }
- if (strcmp(lista[i].artista, "Pericles") == 0) {
- per++;
- va[3]++;
- }
- if (strcmp(lista[i].artista, "Gustavo Mioto") == 0) {
- gus++;
- va[4]++;
- }
- }
- int art = 0, com = 0, beb = 0;
- int vena, venb, venc;
- for (int i = 0; i < 5; i++) {
- if (va[i] > art) {
- art = va[i];
- vena = i;
- }
- if (vb[i] > beb) {
- beb = vb[i];
- venb = i;
- }
- if (vc[i] > com) {
- com = vc[i];
- venc = i;
- }
- }
- char artistaMaisPreferido[30];
- char bebidaMaisPreferida[30];
- char comidaMaisPreferida[30];
- strcpy(artistaMaisPreferido, artistas[vena]);
- strcpy(bebidaMaisPreferida, bebidas[venb]);
- strcpy(comidaMaisPreferida, comidas[venc]);
- int numCheg = 1000000;
- int cheg[chamados];
- for (int i = 0; i < chamados; i++) {
- cheg[i] = lista[i].convidados;
- if (cheg[i] < numCheg) {
- numCheg = cheg[i];
- }
- }
- int maisVotado = 0;
- int vipList[chamados];
- int vipCount = 0;
- for (int i = 0; i < chamados; i++) {
- vip[i] = 0;
- if (strcmp(lista[i].bebida, bebidaMaisPreferida) == 0) {
- vip[i]++;
- }
- if (strcmp(lista[i].artista, artistaMaisPreferido) == 0) {
- vip[i]++;
- }
- if (strcmp(lista[i].comida, comidaMaisPreferida) == 0) {
- vip[i]++;
- }
- if (lista[i].convidados == numCheg) {
- vip[i]++;
- }
- if(vip[i] >= 2){
- lista[i].vip = 1;
- vipCount++;
- }
- }
- int numVip = 0;
- int ind[chamados];
- printf("Artista mais preferido: %s\n", artistaMaisPreferido);
- printf("Bebida mais preferida: %s\n", bebidaMaisPreferida);
- printf("Comida mais preferida: %s\n", comidaMaisPreferida);
- printf("Menor número de convidados que alguém quer trazer: %d\n", numCheg);
- printf("Lista VIP:");
- for (int i = 0; i < chamados; i++) {
- if (lista[i].vip == 1) {
- printf("\n%s", lista[i].nome);
- numVip++;
- ind[numVip-1] = i;
- }
- }
- char listaVip[numVip][50];
- for (int i = 0; i < numVip; i++) {
- strcpy(listaVip[i], lista[ind[i]].nome);
- }
- char aux[50];
- for (int i = 0; i < numVip; i++) {
- for (int j = i + 1; j < numVip; j++) {
- if (strcmp(listaVip[i], listaVip[j]) > 0) {
- strcpy(aux, listaVip[i]);
- strcpy(listaVip[i], listaVip[j]);
- strcpy(listaVip[j], aux);
- }
- }
- }
- printf("\n\nEm ordem alfabética:");
- for (int i = 0; i < numVip; i++) {
- printf("\n%s", listaVip[i]);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment