Advertisement
Avdluna

ASGDUYAGSDUYASD

Aug 28th, 2015
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int coelhos=0,ratos=0,sapos=0,soma,n,num;  
  10.     char animal[3];
  11.  
  12.         scanf("%d", &n);
  13.  
  14.         for(int i = 0; i < n ; i++){
  15.  
  16.             scanf("%d %s", &num, animal);
  17.  
  18.             if(strcmp(animal,"C")== 0){
  19.  
  20.                 coelhos += num;
  21.  
  22.             }
  23.  
  24.             else if(strcmp(animal,"R")== 0){
  25.  
  26.                 ratos += num;
  27.  
  28.             }
  29.  
  30.             else if(strcmp(animal,"S")== 0){
  31.  
  32.                 sapos += num;
  33.  
  34.             }
  35.  
  36.         }
  37.  
  38.         soma = coelhos + ratos + sapos;
  39.  
  40.  
  41.                printf("Total: %d\nTotal de coelhos: %d\nTotal de ratos: %d\nTotal de sapos:                               %d\n",soma,coelhos,ratos,sapos);
  42.                printf("Percentual de coelhos: %.2f %\n", (float)coelhos * 100.0 / soma);
  43.                printf("Percentual de ratos: %.2f %\n", (float)ratos * 100.0 / soma);
  44.                printf("Percentual de sapos: %.2f %\n", (float)sapos * 100.0 / soma);
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement