题目描述
实验
还没学到一些代码,导致做了1个多小时也不知道为什么输出不了,但是除了输出部分前面的思路还是都对的,还是缺少积累。
样例
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,q=0,w=0,e=0,sum;
cin>>n;
for(int i=1;i<=n;i++)
{
char s;
cin>>sum>>s;
if(s=='C')
{
q+=sum;
}
if(s=='R')
{
w+=sum;
}
if(s=='F')
{
e+=sum;
}
}
int tot=q+w+e;
cout<<"Total: "<<q+w+e<<" animals"<<endl;
cout<<"Total coneys: "<<q<<endl;
cout<<"Total rats: "<<w<<endl;
cout<<"Total frogs: "<<e<<endl;
cout<<"Percentage of coneys: "<<fixed<<setprecision(2)<<(double)q/tot*100<<" %"<<endl;
cout<<"Percentage of rats: "<<fixed<<setprecision(2)<<(double)w/tot*100<<" %"<<endl;
cout<<"Percentage of frogs: "<<fixed<<setprecision(2)<<(double)e/tot*100<<" %"<<endl;
return 0;
}