题目描述
逻辑简单,就是格式有点麻烦
样例
#include<iostream>
using namespace std;
#include<cstdio>
int main(){
int n;
scanf("%d",&n);
int x=0,y=0,z=0;
for(int i=1;i<=n;i++){
int a;
char t;
cin>>a>>t;
if(t=='C') x=x+a;
else if(t=='R') y=y+a;
else z=z+a;
}
int s=x+y+z;
printf("Total: %d animals\n",s);
printf("Total coneys: %d\n",x);
printf("Total rats: %d\n",y);
printf("Total frogs: %d\n",z);
printf("Percentage of coneys: %.2lf \%\n",(double)x/s*100);
printf("Percentage of rats: %.2lf \%\n",(double)y/s*100);
printf("Percentage of frogs: %.2lf \%\n",(double)z/s*100);
return 0;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla