Advertisement
Guest User

Untitled

a guest
May 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.05 KB | None | 0 0
  1. //verificação de todos os paises e os seus dados, no ano escolhido
  2. void estuda_paises (int paises, node_t *head_countries, int ano_pais)
  3. {
  4.     node_t *aux = NULL;
  5.     int pais = 0, i = 0, j= 0;
  6.     temp_countries *tmp[STRING_SIZE] = {NULL}, *max[STRING_SIZE] = {NULL}, *min[STRING_SIZE] = {NULL}, *ext[STRING_SIZE] = {NULL};
  7.     aux = head_countries;
  8.  
  9.     while (aux->payload.dt.ano < ano_pais)
  10.       aux = aux->next;
  11.  
  12.     while (aux != NULL && aux->payload.dt.ano == ano_pais){
  13.           pais = 0;
  14.           i = 0;
  15.  
  16.           while (tmp[i] != NULL){
  17.             if (strcmp(tmp[i]->pais, aux->payload.pais) == 0){
  18.               pais++;
  19.               tmp[i]->soma = tmp[i]->soma + aux->payload.temperatura;
  20.               tmp[i]->nelem++;
  21.  
  22.               if (aux->payload.temperatura < tmp[i]->minimo)
  23.                 tmp[i]->minimo = aux->payload.temperatura;
  24.  
  25.               if (aux->payload.temperatura > tmp[i]->maximo)
  26.                 tmp[i]->maximo = aux->payload.temperatura;
  27.             }
  28.             i++;
  29.           }
  30.  
  31.           if (pais == 0){
  32.             tmp[i] = (temp_countries*)checkedMalloc(sizeof(temp_countries));
  33.             strcpy(tmp[i]->pais, aux->payload.pais);
  34.             printf("%s\n", tmp[i]->pais);
  35.             tmp[i]->minimo = aux->payload.temperatura;
  36.             tmp[i]->maximo = aux->payload.temperatura;
  37.             tmp[i]->nelem = 1;
  38.             tmp[i]->soma = aux->payload.temperatura;
  39.           }
  40.  
  41.           aux = aux->next;
  42.  
  43.     }
  44.  
  45.     for (j = 0; j < i; j++){
  46.       tmp[j]->media = tmp[j]->soma / tmp[j]->nelem;
  47.       tmp[j]->extremo = tmp[j]->minimo - tmp[j]->maximo;
  48.       max[j] = tmp[j];
  49.       min[j] = tmp[j];
  50.       ext[j] = tmp[j];
  51.     }
  52.  
  53.     system("clear");
  54.     paises_quentes (i, max);
  55.     paises_frios (i, min);
  56.     paises_extremos (i, ext);
  57.  
  58.     printf("  Países + quentes\t\t  Países + frias\t\t Países + extremas\n\n");
  59.     for (j = 0; j < paises; j++)
  60.         printf(" %s-> %f\t\t%s-> %f\t\t%s-> %f \n", max[j]->pais, max[j]->media, min[j]->pais, min[j]->media, ext[j]->pais, ext[j]->extremo);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement