Advertisement
Valdinei

Questão infiliz

Oct 31st, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.  
  6.     int i, n, k, num_fig[10000], fig_maria = 0, fig_joao = 0, soma_joao = 0, soma_maria = 0;
  7.     int count = 0;
  8.  
  9.     scanf("%d", &n);
  10.  
  11.     for (i = 0; i < n; i++)
  12.     {
  13.         scanf("%d", &num_fig[i]);
  14.        
  15.         //Se for par
  16.         if (num_fig[i]%2 == 0)
  17.         {
  18.             //Mais uma figurinha de joao
  19.             fig_joao++;
  20.  
  21.             //Verifica as repetições
  22.             for (k = 0; k < n; k++)
  23.             {
  24.                 if (num_fig[i] == num_fig[k])
  25.                     count++;
  26.             }
  27.  
  28.             //Soma apenas se não tiverem figurinhas repitidas
  29.             if (count == 1)
  30.                 soma_joao += num_fig[i];
  31.  
  32.             count = 0;
  33.         }
  34.  
  35.         else
  36.         {
  37.             //Mais uma figurinha de maria
  38.             fig_maria++;
  39.  
  40.            
  41.             //Verifica as repetições
  42.             for (k = 0; k < n; k++)
  43.             {
  44.                 if (num_fig[i] == num_fig[k])
  45.                     count++;
  46.             }
  47.  
  48.             //Soma apenas se não tiverem figurinhas repitidas
  49.             if (count == 1)
  50.                 soma_maria += num_fig[i];  
  51.  
  52.             count = 0; 
  53.         }
  54.     }
  55.  
  56.     if (soma_joao > soma_maria)
  57.     {
  58.         printf("%d\n%d\n%d\n", fig_joao, fig_maria, soma_joao);
  59.     }
  60.  
  61.  
  62.     else
  63.     {
  64.         printf("%d\n%d\n%d\n", fig_joao, fig_maria, soma_maria);
  65.     }
  66.  
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement