题目描述
blablabla
样例
#include <iostream>
using namespace std;
int main()
{
int a, n;
char c;
scanf("%d", &n);
int sum = 0, C = 0, R = 0, F = 0; //计数器sum表示总和,C 表示兔子(coney),R 表示老鼠(rat),F 表示青蛙(frog)
while (n -- )
{
cin>>a>>c;
if(c=='C') C+=a;
if(c=='R') R+=a;
else if(c=='F') F+=a;
sum+=a;
}
double c2=(double)C/(double)sum*100;
double r=(double)R/(double)sum*100;
double f=(double)F/(double)sum*100;
//这里需要浮点数来存,注意一定要强制类型转换
printf("Total: %d animals\n", sum);
printf("Total coneys: %d\n", C);
printf("Total rats: %d\n", R);
printf("Total frogs: %d\n", F);
printf("Percentage of coneys: %.2lf %%\n", c2);
printf("Percentage of rats: %.2lf %%\n", r);
printf("Percentage of frogs: %.2lf %%\n", f);
return 0;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla