fork download
  1. # include <stdio.h>
  2.  
  3. int main (void)
  4. {
  5. int i, tam, qtde, total, coelhos=0, ratos=0, sapos=0;
  6. char tipo;
  7. float media;
  8.  
  9. scanf("%d", &tam);
  10. for(i=0 ; i<tam ; i++)
  11. {
  12. fflush(stdin); //flush here
  13. scanf("%d", &qtde);
  14. fflush(stdin); // flush here
  15. scanf(" %c", &tipo); // use a space before %c
  16.  
  17. if(qtde >= 1 && qtde <= 15)
  18. {
  19. if(tipo == 'C')
  20. {
  21. coelhos = coelhos + qtde;
  22. }
  23. else if(tipo == 'R')
  24. {
  25. ratos = ratos + qtde;
  26. }
  27. else if(tipo == 'S')
  28. {
  29. sapos = sapos + qtde;
  30. }
  31. }
  32. }
  33. total = coelhos + ratos + sapos;
  34. printf("Total: %d cobaias\n", total);
  35. printf("Total de coelhos: %d\n", coelhos);
  36. printf("Total de ratos: %d\n", ratos);
  37. printf("Total de sapos: %d\n", sapos);
  38.  
  39. media = ((float)coelhos / total) * 100;
  40. printf("Percentual de coelhos: %.2f %%\n", media);
  41.  
  42. media = ((float)ratos / total) * 100;
  43. printf("Percentual de ratos: %.2f %%\n", media);
  44.  
  45. media = ((float)sapos / total) * 100;
  46. printf("Percentual de sapos: %.2f %%\n", media);
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 16064KB
stdin
10
10 C
6 R
15 S
5 C
14 R
9 C
6 R
8 S
5 C
14 R
stdout
Total: 92 cobaias
Total de coelhos: 29
Total de ratos: 40
Total de sapos: 23
Percentual de coelhos: 31.52 %
Percentual de ratos: 43.48 %
Percentual de sapos: 25.00 %