用时20分钟,没有一次性AC的原因是:百分号前没加空格。
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
//freopen("xxx.in","r",stdin);
//freopen("yyy.out","w",stdout);
int n,s;
double c=0,r=0,f=0,he=0;
char p;
cin >> n;
for(int i=0;i<n;i++)
{
cin >> s >> p;
he+=s;
if(p=='C')
{
c+=s;
}
else if(p=='R')
{
r+=s;
}
else if(p=='F')
{
f+=s;
}
}
cout << "Total: " << he << " animals" << '\n';
cout << "Total coneys: " << c << '\n';
cout << "Total rats: " << r << '\n';
cout << "Total frogs: " << f << '\n';
cout << "Percentage of coneys: " << fixed << setprecision(2) << (c/he*100) << " %" << '\n';
cout << "Percentage of rats: " << fixed << setprecision(2) << (r/he*100) << " %" << '\n';
cout << "Percentage of frogs: " << fixed << setprecision(2) << (f/he*100) << " %" << '\n';
//fclose(stdin);
//fclose(stdout);
return 0;
}