#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
#define N 1000
int main(void){
int a[N],n=0;
while(scanf("%d",&n) != EOF){
double A[5]={0},k1=0,k3=0;
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=0;i<n;i++)
{
if(a[i]%5==0&&a[i]%2==0) A[0] += a[i];
if(a[i]%5==1) A[1] += a[i]*pow((double)-1,k1++);
if(a[i]%5==2) A[2]++;
if(a[i]%5==3)
{
A[3] += a[i];
k3++;
}
if(a[i]%5==4)
{
if(A[4] < a[i]) A[4]=a[i];
}
}
if(k3) A[3] = A[3]/k3;
for(int i=0;i<4;i++)
{
if(A[i]&&(A[i]-(int)A[i])==0) printf("%.0lf ",A[i]);
else if(A[i]) printf("%.1lf ",A[i]);
else printf("N ");
}
if(A[4]) printf("%.0lf",A[4]);
else printf("N");
}
return 0;
}
答案错误 9%
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
int main(){
int n, num;
int a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0;
bool existA1 = false, existA2 = false;
int countA4 = 0;
scanf("%d", &n);
for(int i = 0, j = 0; i < n; i++){
scanf("%d", &num);
if(num % 5 == 0){
if(num % 2 == 0){
existA1 = true;
a1 += num;
}
}
else if(num % 5 == 1){
existA2 = true;
a2 += num * pow((double)(-1), j);
j++;
}
else if(num % 5 == 2){
a3++;
}
else if(num % 5 == 3){
a4 += num;
countA4++;
}
else{
a5 = (num > a5 ? num : a5);
}
}
if(existA1){
printf("%d", a1);
}
else{
printf("%c", 'N');
}
if(existA2){
printf(" %d", a2);
}
else{
printf(" %c", 'N');
}
if(a3 != 0){
printf(" %d", a3);
}
else{
printf(" %c", 'N');
}
if(countA4 != 0){
printf(" %.1f", (double)a4 / countA4);
}
else{
printf(" %c", 'N');
}
if(a5 != 0){
printf(" %d\n", a5);
}
else{
printf(" %c\n", 'N');
}
return 0;
}