1.题目描述
2.完整代码
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;
int main(){
int N;
cin >> N;
int s[N];
int a=0,b=0,j=0,k=0,max=0,num1=0;
double q,y=0;
for(int i=0;i<N;i++){
cin >> s[i];
if(s[i]%5==0&&s[i]%2==0) a=a+s[i];
if(s[i]%5==1){
b=b+pow(-1,j)*s[i];
j++;
}
if(s[i]%5==2) k++;
if(s[i]%5==3){
num1 = num1+s[i];
y++;
}
if(s[i]%5==4){
if(s[i]>max) max=s[i];
}
}
q=(num1)/y;
if(a==0) cout << "N ";
else cout << a << " ";
if(j==0) cout << "N ";
else cout << b << " ";
if(k==0) cout << "N ";
else cout << k << " ";
if(y==0) cout << "N ";
else printf("%.1lf ",q);
if(max==0) cout << "N";
else cout << max;
}
注意:输出第4个分类精确到小数点后1位时,不要使用setprecision(),不然有测试不能通过。直接使用printf( )。
由于水平有限,如有问题欢迎评论区留言!!