Submit: 70 Solved: 64
[ Submit ][ Status ][ Web Board ]
Description
The standard for the purchase of oranges from a certain origin is to determine the grade of oranges according to the maximum cross-sectional diameter of the oranges. >=85 is the first-class fruit, >=75 and <85 is the second-class fruit, >=65 and <75 is the third-class fruit, < 65 is the fourth grade fruit. Given the diameters of n oranges, please give the number of oranges of each grade according to the classification criteria.
#include <iostream>
using namespace std;
int main()
{
int n1=0, n2=0, n3=0, n4=0;
int i, n, diameter;
cin>>n; //Enter the number of oranges
for(i=1; i<=n; i++)
{
cin>>diameter; //Enter the maximum cross-sectional diameter of the orange
//begin
//end
}
cout<<"1:"<<n1<<endl;
cout<<"2:"<<n2<<endl;
cout<<"3:"<<n3<<endl;
cout<<"4:"<<n4<<endl;
return 0;
}
Input
The total number of tangerines and the maximum cross-sectional diameter of each tangerine
Output
Number of first-class fruits
Number of secondary fruits
Number of tertiary fruits
Sample Input
10
90 88 76 85 60 65 75 68 73 84
Sample Output
1:3
2:3
3:3
4:1
HINT
When submitting, only submit the code between the line where begin is located and the line where end is located
Source
Code:
#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;
}