AcWing 718. 实验
原题链接
困难
作者:
学不会算法不改名--
,
2024-02-28 23:37:45
,
所有人可见
,
阅读 20
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n;
cin>>n;
int c=0,r=0,f=0;
for(int i=0;i<n;i++)
{
int k;
char t;
cin>>k>>t;//scanf在读入字符时不会自动过滤空格,回车,制表符tab,cout能自动过滤这些
//第二种写法:scanf("%d %c",&k,&t); 中间要加空格手动过滤空格
if(t=='C') c+=k;
else if (t=='R') r+=k;
else f+=k;
}
int s=c+r+f;
printf("Total: %d animals\n",s);
printf("Total coneys: %d\n",c);
printf("Total rats: %d\n",r);
printf("Total frogs: %d\n",f);
printf("Percentage of coneys: %.2lf %%\n",(double)c/s*100);
printf("Percentage of rats: %.2lf %%\n",(double)r/s*100);
printf("Percentage of frogs: %.2lf %%\n",(double)f/s*100);
return 0;
}