AcWing 718. 实验
原题链接
困难
作者:
wnnSam
,
2019-05-13 17:40:49
,
所有人可见
,
阅读 1347
C++ 代码
#include <iostream>
#include <string>
#include <numeric>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin >> n;
int numbers[n];
string animals[n];
for(int i = 0;i < n;i++)
{
cin >> numbers[i] >> animals[i];
}
double renum = accumulate(numbers,numbers + n,0);
cout << "Total: " << renum << " animals" << endl;
double coneys,rats,frogs = 0.00;
for(int k = 0;k < n;k++)
{
if(animals[k] == "C")
{
coneys += numbers[k];
}
else if(animals[k] == "R")
{
rats += numbers[k];
}
else
{
frogs += numbers[k];
}
}
cout << "Total coneys: " << coneys << endl;
cout << "Total rats: " << rats << endl;
cout << "Total frogs: " << frogs << endl;
cout << setiosflags(ios::fixed) << setprecision(2);
cout << "Percentage of coneys: " << coneys*100/renum << " %" << endl;
cout << "Percentage of rats: " << rats*100/renum << " %" << endl;
cout << "Percentage of frogs: " << frogs*100/renum << " %" << endl;
return 0;
}