AcWing 718. 实验
原题链接
困难
作者:
垫底抽風
,
2021-08-17 16:01:11
,
所有人可见
,
阅读 1144
参考文献
C++ 代码
#include<bits/stdc++.h>
using namespace std;
int n,i,a,s,c,r,f;
char ch;
int main()
{
cin>>n;
for(i=1;i<=n;i++){
cin>>a>>ch;
if(ch=='C')c=c+a;
if(ch=='R')r=r+a;
if(ch=='F')f=f+a;
s=s+a;
}
cout<<"Total: "<<s<<" animals"<<endl;
cout<<"Total coneys: "<<c<<endl;
cout<<"Total rats: "<<r<<endl;
cout<<"Total frogs: "<<f<<endl;
cout<<"Percentage of coneys: "<<fixed<<setprecision(2)<<c*100.0/s<<" %"<<endl;
cout<<"Percentage of rats: "<<fixed<<setprecision(2)<<r*100.0/s<<" %"<<endl;
cout<<"Percentage of frogs: "<<fixed<<setprecision(2)<<f*100.0/s<<" %";
}