Header Ads

Header ADS

Solution of URI 1094::Experiments

Before seeing the solution make sure that you have tried enough. Don’t copy the whole code, just find out the logic. If you feel any problemyou will inform me by comment.




#include <stdio.h>
int main() {
    int N,i,num;
    long int Atotal=0,Ctotal=0,Rtotal=0,Stotal=0;
    float Cper,Rper,Sper;
    char ch[2];

    scanf("%d",&N);
    for(i=1; i<=N; i++)
    {
        scanf("%d%s",&num,&ch);
        if(ch[0]=='C') Ctotal+=num;
        else if(ch[0]=='R') Rtotal+=num;
        else if(ch[0]=='S') Stotal+=num;
    }

    Atotal=Ctotal+Rtotal+Stotal;
    Cper=(Ctotal/(Atotal*1.0))*100.00;
    Rper=(Rtotal/(Atotal*1.0))*100.00;
    Sper=(Stotal/(Atotal*1.0))*100.00;
    printf("Total: %ld cobaias\n",Atotal);
    printf("Total de coelhos: %ld\n",Ctotal);
    printf("Total de ratos: %ld\n",Rtotal);
    printf("Total de sapos: %ld\n",Stotal);
    printf("Percentual de coelhos: %.2f %%\n",Cper);
    printf("Percentual de ratos: %.2f %%\n",Rper);
    printf("Percentual de sapos: %.2f %%\n",Sper);

    return 0;
}

No comments

Theme images by konradlew. Powered by Blogger.