AcWing 718. 实验
原题链接
简单
作者:
SayYong
,
2024-09-29 23:24:54
,
所有人可见
,
阅读 1
#include <iostream>
using namespace std;
int total = 0.0;
int total_C = 0.0;
int total_R = 0.0;
int total_F = 0.0;
int main(void)
{
int n;
cin >> n;
while (n--) {
int x;
char op;
cin >> x >> op;
if (op == 'C') {
total_C += x;
} else if (op == 'R') {
total_R += x;
} else if (op == 'F') {
total_F += x;
}
}
total = total_C + total_R + total_F;
printf("Total: %d animals\n", total);
printf("Total coneys: %d\n", total_C);
printf("Total rats: %d\n", total_R);
printf("Total frogs: %d\n", total_F);
printf("Percentage of coneys: %.2f %\n", total_C * 100.0 / total);
printf("Percentage of rats: %.2f %\n", total_R * 100.0 / total);
printf("Percentage of frogs: %.2f %\n", total_F * 100.0 / total);
return 0;
}