Advertisement
Guest User

gomercindo tmp 2

a guest
Nov 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include<stdlib.h>
  3.  
  4. typedef struct celula{
  5.     long long int valor;
  6.   int id;
  7.   int prox;
  8. }celula;
  9.  
  10. /* ---------------------------------- */
  11. int main(void)
  12. {
  13.   int n;
  14.   celula *vector = calloc(n,sizeof(celula));
  15.   scanf("%d",&n);
  16.  
  17.   long long int ultimo;
  18.   for(int a = 0; a < n; a++)
  19.   {
  20.     int id,prox;
  21.     long long int valor;
  22.     scanf("%d%lld%d",&id,&valor,&prox);
  23.     if(prox != -1)
  24.     {
  25.       vector[a].prox = prox;
  26.       vector[a].valor = valor;
  27.       vector[a].id = id;
  28.     }else
  29.       ultimo = valor;
  30.   }
  31.   printf("%lld\n",vector[0].valor);
  32.   for(int a = 0; a < n; a++)
  33.   {
  34.     for(int b = a; b < n; b++)
  35.     {
  36.       if(vector[a].prox == vector[b].id && vector[a].id)
  37.       {
  38.         printf("%lld\n",vector[b].valor);
  39.         vector[a].id = vector[b].id = -2;
  40.       }
  41.     }
  42.   }
  43.   printf("%lld\n",ultimo);
  44.   free(vector);
  45.   return 0;
  46. }
  47. /* ---------------------------------- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement