AcWing 718. 实验
原题链接
简单
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n=0,m=0,sum=0,sum1=0,sum2=0,sum3=0;
char t;
double s1,s2,s3;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>m>>t;
if(t=='C')
sum1+=m;
else if(t=='R')
sum2+=m;
else
sum3+=m;
sum+=m;
}
s1=(double)sum1/(double)sum*100;
s2=(double)sum2/(double)sum*100;
s3=(double)sum3/(double)sum*100;
printf("Total: %d animals\n",sum);
printf("Total coneys: %d\n",sum1);
printf("Total rats: %d\n",sum2);
printf("Total frogs: %d\n",sum3);
printf("Percentage of coneys: %.2lf %\n",s1);
printf("Percentage of rats: %.2lf %\n",s2);
printf("Percentage of frogs: %.2lf %\n",s3);
return 0;
}