Submit: 70 Solved: 64
[ Submit][ Status][ Web Board]
Description
某产地的橘子收购标准是根据橘子最大横切面直径来确定橘子的等级,>=85是一等果,>=75 且<85 是二等果,>=65且<75是三等果,<65是四等果。给出n个橘子的直径,请按照分类标准,给出每种等级橘子的数量。
#include <iostream>
using namespace std;
int main()
{
int n1=0, n2=0, n3=0, n4=0;
int i, n, diameter;
cin>>n; //输入橘子个数
for(i=1; i<=n; i++)
{
cin>>diameter; //输入橘子最大横切面直径
//begin
//end
}
cout<<"1:"<<n1<<endl;
cout<<"2:"<<n2<<endl;
cout<<"3:"<<n3<<endl;
cout<<"4:"<<n4<<endl;
return 0;
}
Input
橘子的总个数和每个橘子的最大横切面直径
Output
一等果的数量
二等果的数量
三等果的数量
Sample Input
10
90 88 76 85 60 65 75 68 73 84
Sample Output
1:3
2:3
3:3
4:1
HINT
提交时只提交begin所在行和end所在行之间的代码
Source
代码:
#include <iostream>
using namespace std;
int main()
{
int n1=0, n2=0, n3=0, n4=0;
int i, n, diameter;
cin>>n; //输入橘子个数
for(i=1; i<=n; i++)
{
cin>>diameter; //输入橘子最大横切面直径
if(diameter>=85)n1++;
else if(diameter<85&&diameter>=75)n2++;
else if(diameter<75&&diameter>=65)n3++;
else n4++;
}
cout<<"1:"<<n1<<endl;
cout<<"2:"<<n2<<endl;
cout<<"3:"<<n3<<endl;
cout<<"4:"<<n4<<endl;
return 0;
}