题目描述
blablabla
样例
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int N;
cin >> N; // 读取实验次数
int totalAnimals = 0; // 总动物数
int totalConeys = 0; // 兔子总数
int totalRats = 0; // 老鼠总数
int totalFrogs = 0; // 青蛙总数
// 读取每行数据并统计
for (int i = 0; i < N; ++i) {
int A;
char T;
cin >> A >> T;
totalAnimals += A; // 增加总动物数
switch (T) {
case 'C':
totalConeys += A;
break;
case 'R':
totalRats += A;
break;
case 'F':
totalFrogs += A;
break;
}
}
// 输出结果
cout << "Total: " << totalAnimals << " animals" << endl;
cout << "Total coneys: " << totalConeys << endl;
cout << "Total rats: " << totalRats << endl;
cout << "Total frogs: " << totalFrogs << endl;
// 输出百分比,保留两位小数
cout << fixed << setprecision(2);
cout << "Percentage of coneys: " << (100.0 * totalConeys / totalAnimals) << "%" << endl;
cout << "Percentage of rats: " << (100.0 * totalRats / totalAnimals) << "%" << endl;
cout << "Percentage of frogs: " << (100.0 * totalFrogs / totalAnimals) << "%" << endl;
return 0;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla