填空题B-空气污染指数
时间: 1ms 内存:128M
描述:
注:本题只需要提交标记为修改部分之间的代码,请按照C++方式提交。
空气污染指数为0-50,空气质量级别为一级,空气质量状况属于优。
空气污染指数为51-100,空气质量级别为二级,空气质量状况属于良。
空气污染指数为101-150,空气质量级别为三级,空气质量状况属于轻度污染。
空气污染指数为151-200,空气质量级别为四级,空气质量状况属于中度污染。
空气污染指数为201-300,空气质量级别为五级,空气质量状况属于重度污染。
空气污染指数大于300,空气质量级别为六级,空气质量状况属于严重污染。
给出n天的空气污染指数,请按照分类标准,给出每种空气质量级别的天数。#include <iostream>
using namespace std;
int main()
{
int n1=0,n2=0,n3=0,n4=0,n5=0,n6=0;
int i,n,API;
cin>>n;
for(i=1; i<=n; i++)
{
cin>>API;
/*
请填写该部分代码
*/
}
cout<<"1:"<<n1<<endl;
cout<<"2:"<<n2<<endl;
cout<<"3:"<<n3<<endl;
cout<<"4:"<<n4<<endl;
cout<<"5:"<<n5<<endl;
cout<<"6:"<<n6<<endl;
return 0;
}
输入:
n和n天的空气污染指数
输出:
空气质量为一级、二级、三级、四级、五级、六级的天数
示例输入:
15
0 50 51 100 101 150 151 200 201 300 400 301 300 250 200
示例输出:
1:2
2:2
3:2
4:3
5:4
6:2
提示:
参考答案(内存最优[552]):
program p1000(Input,Output);
var
a,b,c,d,e,f,sum,num,i:integer;
begin
read(sum);
a := 0;
b := 0;
c := 0;
d := 0;
e := 0;
f := 0;
for i:=1 to sum do
begin
read(num);
if num>300 then
f := f+1
else if num>200 then
e := e+1
else if num>150 then
d := d+1
else if num>100 then
c := c+1
else if num>50 then
b := b+1
else
a := a+1;
end;
writeln('1:',a);
writeln('2:',b);
writeln('3:',c);
writeln('4:',d);
writeln('5:',e);
writeln('6:',f);
end.
参考答案(时间最优[0]):
#include <iostream>
using namespace std;
int main()
{
int n1=0,n2=0,n3=0,n4=0,n5=0,n6=0;
int i,n,API;
cin>>n;
for(i=1; i<=n; i++)
{
cin>>API;
if(API>300)
n6++;
else if(API>200)
n5++;
else if(API>150)
n4++;
else if(API>100)
n3++;
else if(API>50)
n2++;
else if(API>=0)
n1++;
}
cout<<"1:"<<n1<<endl;
cout<<"2:"<<n2<<endl;
cout<<"3:"<<n3<<endl;
cout<<"4:"<<n4<<endl;
cout<<"5:"<<n5<<endl;
cout<<"6:"<<n6<<endl;
return 0;
}
题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。