题目描述
实验 较麻烦
样例
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n,a=0,c=0,r=0,f=0,t,s=0,i;
cin>>n;
for ( i=1;i<=n;i++)//循环加判断
{
char q;
cin>>a>>q;
t=a;
if(q=='C') c+=a;
if(q=='R') r+=a;
if(q=='F') f+=a;
s+=t;
}
double s1=0,s2=0,s3=0;//注意变量精度
s1=(double)c/(double)s*100;
s2=(double)r/(double)s*100;
s3=(double)f/(double)s*100;
printf("Total: %d animals\nTotal coneys: %d\nTotal rats: %d\nTotal frogs: %d\n",s,c,r,f);
printf("Percentage of coneys: %.2lf %\nPercentage of rats: %.2lf %\nPercentage of frogs: %.2lf %",s1,s2,s3);//注意换行
return 0;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla