718.实验
作者:
不想考试
,
2024-11-16 15:38:00
,
所有人可见
,
阅读 1
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
char a;
int num,sum = 0,c = 0, r = 0,f = 0;
for(int i = 0;i < n;i ++)
{
scanf("%d %c\n",&num,&a);
if( a == 'C') c += num;
if( a == 'R') r += num;
if( a == 'F') f += num;
}
sum = c + r + f;
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",(double)c / sum * 100);
printf("Percentage of rats: %.2lf %%\n",(double)r / sum * 100);
printf("Percentage of frogs: %.2lf %%\n",(double)f / sum * 100);
return 0;
}
scanf在读入字符时,不会自动过滤空格、回车、tab
cin会自动过滤
可以用else if