Advertisement
Guest User

asdasd

a guest
Oct 16th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. //se declaran los structs
  5.  struct region {
  6.         char nombre[50];
  7.         int numero;
  8.         unsigned int votos[6];
  9. };
  10.  struct candidato {
  11.         char nombre[50];
  12.         unsigned int votos;
  13. };
  14.  struct elecciones {
  15.         struct region regiones[15];
  16.         struct candidato candidatos[6];
  17.         int poblacionChilena;
  18. };
  19. struct auxiliares {
  20.     int numero;
  21.     int votos;
  22. };
  23.  
  24.  
  25. //se inicia el programa
  26. int main()
  27. {
  28.     struct elecciones datos;
  29.     int i,TotalDeVotos=0,j;
  30.     char *regionesChile[15] = {"Tarapaca", "Antofagasta", "Atacama", "Coquimbo", "Valparaiso", "O'Higgins", "Maule", "Bio-Bio", "La Araucania", "Los Lagos", "Aysen", "Magallanes", "Santiago", "Los Rios", "Arica y Parinacota"};
  31.     char *candidatosChile[6] = {"Sebastian Pinera", "Beatriz Sanchez", "Alejandro Guillier", "MEO", "Carolina Goic", "Alejandro Navarro"};
  32.  
  33.     //copio los datos de los arreglos a los structs
  34.     for (i=0; i<15; ++i)
  35.     {
  36.         strcpy(datos.regiones[i].nombre,regionesChile[i]);
  37.         datos.regiones[i].numero=i;
  38.     }
  39.  
  40.     for (i = 0; i<6; ++i)
  41.     {
  42.         strcpy(datos.candidatos[i].nombre,candidatosChile[i]);
  43.     }
  44.  
  45.     //obtengo la poblacion chilena
  46.     scanf("%d",&datos.poblacionChilena);
  47.  
  48.     //se realizan las votaciones
  49.     for (j = 0; j < 15; ++j)
  50.     {
  51.         for ( i = 0; i < 6; ++i)
  52.         {
  53.             scanf("%d",&datos.regiones[j].votos[i]);
  54.             TotalDeVotos+=datos.regiones[j].votos[i];
  55.            
  56.         }
  57.     }
  58.    
  59.     int aSumar;
  60.     //calculo el numero de votos que tiene cada candidato
  61.     for (j = 0; j < 6; ++j)
  62.     {
  63.         for ( i = 0; i < 15; ++i)
  64.         {
  65.             aSumar+=datos.regiones[i].votos[j];
  66.             datos.candidatos[j].votos+=aSumar;
  67.             printf("%s \n",datos.candidatos[j].nombre);
  68.             aSumar=0;
  69.             if(datos.candidatos[j].votos>TotalDeVotos)
  70.             {
  71.                 printf("ERR0R\n");
  72.             }
  73.         }
  74.             printf("%d\n",datos.candidatos[j].votos);
  75.     }
  76.  
  77.     //Saco el culiao con mas votos
  78.     struct auxiliares aux1,aux2;
  79.     for (i = 0; i < 6; ++i)
  80.     {
  81.         if (datos.candidatos[i].votos>=aux1.votos)
  82.         {
  83.             aux2.votos=aux1.votos;
  84.             aux2.numero=aux1.numero;
  85.             aux1.votos=datos.candidatos[i].votos;
  86.             aux1.numero=i;
  87.         }
  88.     }
  89.    
  90.  
  91.     //Printeo los resultados
  92.  
  93.     if(aux1.votos>(TotalDeVotos/2)+1)
  94.     {
  95.         printf("Con un total de %d votos, se declara Presidente a: %s con %d votos.",TotalDeVotos,datos.candidatos[aux1.numero].nombre,datos.candidatos[aux1.numero].votos);
  96.     }
  97.     else
  98.     {  
  99.         printf("Con un total de %d votos, se declara segunda vuelta entre: %s y %s con %d y %d votos respectivamente.",TotalDeVotos,datos.candidatos[aux1.numero].nombre,datos.candidatos[aux2.numero].nombre,datos.candidatos[aux1.numero].votos,datos.candidatos[aux2.numero].votos);
  100.     }
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement