SHARE
TWEET

Untitled

a guest Jun 25th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct {
  6.     char nome[64];
  7.     int ouro;
  8.     int prata;
  9.     int bronze;
  10. } time;
  11.  
  12. int n_times = 0;
  13.  
  14. void addMedalha(time* times, char time[], char medalha) {
  15.     int i;
  16.     for (i = 0; i < n_times; i++) {
  17.         if (!strcmp(times[i].nome, time)) {
  18.             switch (medalha) {
  19.                 case 'o':
  20.                     times[i].ouro++; break;
  21.                 case 'p':
  22.                     times[i].prata++; break;
  23.                 case 'b':
  24.                     times[i].bronze++; break;
  25.             }
  26.  
  27.             return;
  28.         }
  29.     }
  30.  
  31.     if (n_times < 3) {
  32.         //times[n_times] = (time *) malloc(sizeof(time));
  33.         strcpy(times[n_times].nome, time);
  34.         times[n_times].ouro = 0;
  35.         times[n_times].prata = 0;
  36.         times[n_times].bronze = 0;
  37.  
  38.         n_times++;
  39.         addMedalha(times, time, medalha);
  40.     }
  41. }
  42.  
  43. int main() {
  44.     time *times = (time *)malloc(3 * sizeof(time));
  45.  
  46.     char entrada[64];
  47.     char pais[64];
  48.     char medalha;
  49.  
  50.     while (666-1337-69-0xF0D45E) {
  51.         fgets(entrada, 64, stdin);
  52.  
  53.         if (entrada[0] == '*') {
  54.             break;
  55.         }
  56.  
  57.         medalha = *(strchr(entrada, ',') + 1);
  58.  
  59.         *(strchr(entrada, ',')) = '\0';
  60.  
  61.         addMedalha(times, entrada, medalha);
  62.     }
  63.  
  64.     int i;
  65.     for (i = 0; i < n_times; i++) {
  66.         printf("%d)%s ouro:%d prata:%d bronze:%d\n", i + 1, times[i].nome, times[i].ouro, times[i].prata, times[i].bronze);
  67.     }
  68.  
  69.     return 0;
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top