AcWing 718. 实验
原题链接
困难
作者:
时壹
,
2024-04-08 17:46:27
,
所有人可见
,
阅读 5
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a,sum=0,res[3]={0,0,0};
char c;
string m[3]={"coneys","rats","frogs"};
cin>>n;
while(n)
{
cin>>a>>c;
sum+=a;
if(c=='C')
res[0]+=a;
else if(c=='R')
res[1]+=a;
else
res[2]+=a;
n--;
}
printf("Total: %d animals\n",sum);
for(int j=0;j<3;j++)
printf("Total %s: %d\n",m[j].c_str(),res[j]);
for(int x=0;x<3;x++)
printf("Percentage of %s: %.2lf %\n",m[x].c_str(),100*res[x]*1.0/sum*1.0);
return 0;
}