题目描述
这个题题目比较难理解,而且题也挺不好做的。希望能为之后的题打下一个基础吧。
样例
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
int n,a,A=0,c=0,r=0,f=0;
string t;
double x,y,z;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a>>t;
A+=a;
if(t=="C")c+=a;
else if(t=="R")r+=a;
else f+=a;
}
x=(double)c*100/A;
y=(double)r*100/A;
z=(double)f*100/A;
cout<<"Total: "<<A<<" animals"<<endl;
cout<<"Total coneys: "<<c<<endl;
cout<<"Total rats: "<<r<<endl;
cout<<"Total frogs: "<<f<<endl;
cout<<fixed<<setprecision(2)<<"Percentage of coneys: "<<x<<" %"<<endl;
cout<<fixed<<setprecision(2)<<"Percentage of rats: "<<y<<" %"<<endl;
cout<<fixed<<setprecision(2)<<"Percentage of frogs: "<<z<<" %"<<endl;
return 0;
}