AcWing 718. 实验
原题链接
困难
作者:
林田惠
,
2020-10-31 14:36:00
,
所有人可见
,
阅读 345
C++ 代码
#include<stdio.h>
int main(void)
{
char T,zero;
int n,i,number,sum=0;
int c=0,r=0,f=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d %c",&number,&T);
sum+=number;
if(T=='C') c+=number;//一开始写成c++,r++,f++一直不知道哪错了,想到困...隔天早上发现是数量不是次数
else if(T=='R') r+=number;
else if(T=='F') f+=number;
}
printf("Total: %d animals\n",sum);
printf("Total coneys: %d\n",c);
printf("Total rats: %d\n",r);
printf("Total frogs: %d\n",f);
printf("Percentage of coneys: %.2lf %%\n",c/(c+r+f+0.0)*100);
printf("Percentage of rats: %.2lf %%\n",r/(c+r+f+0.0)*100);
printf("Percentage of frogs: %.2lf %%\n",f/(c+r+f+0.0)*100);
return 0;
}