AcWing 718. 实验
原题链接
简单
作者:
辰溪.
,
2024-11-14 21:24:02
,
所有人可见
,
阅读 1
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n,x,sum=0;
int cs=0,rs=0,fs=0;
char y;
cin>>n;
int i;
for(i=1;i<=n;i++)
{
cin>>x>>y;
sum+=x;
if(y=='C')
cs+=x;
else if(y=='R')
rs+=x;
else if(y=='F')
fs+=x;
}
cout<<"Total: "<<sum<<" animals"<<endl;
cout<<"Total coneys: "<<cs<<endl;
cout<<"Total rats: "<<rs<<endl;
cout<<"Total frogs: "<<fs<<endl;
cout<<"Percentage of coneys: "<<fixed<<setprecision(2)<<double(cs*1.00/sum*100)<<" %"<<endl;
cout<<"Percentage of rats: "<<fixed<<setprecision(2)<<double(rs*1.00/sum*100)<<" %"<<endl;
cout<<"Percentage of frogs: "<<fixed<<setprecision(2)<<double(fs*1.00/sum*100)<<" %"<<endl;
return 0;
}