# 一、题干

1012 数字分类 (20)（20 分）

A1 = 能被5整除的数字中所有偶数的和；

A2 = 将被5除后余1的数字按给出顺序进行交错求和，即计算n1-n2+n3-n4...；

A3 = 被5除后余2的数字的个数；

A4 = 被5除后余3的数字的平均数，精确到小数点后1位；

A5 = 被5除后余4的数字中最大数字。

13 1 2 3 4 5 6 7 8 9 10 20 16 18


30 11 2 9.7 9


8 1 2 4 5 6 7 9 16


N 11 2 N 9

# 二、分析

public static int[] getData() throws IOException {
String[] targetString = string.split(" ");
int size = Integer.parseInt(targetString[0]);
int[] target = new int[size];
for (int i = 0 ; i < target.length ; i ++)
target[i] = Integer.parseInt(targetString[i + 1]);
return target;
}

public static void main() throws IOException {
int[] target = getData();
int A1Sum = 0;//A1结果
int A2Count = 0;//A2计数变量
int A2Sum = 0;//A2结果
int A3Count = 0;//A3结果
int A4Sum = 0;//A4求和
int A4Count = 0;//A4计数
boolean A2F = true;//因为可能A2Count得到的是0
int A5Max = 0;
for (int i = 0 ; i < target.length ; i ++) {
switch (target[i] % 10) {
case 1:
case 6:
if (A2Count % 2 == 0)
A2Sum += target[i];
else
A2Sum -= target[i];
A2Count ++;
A2F = false;
break;
case 2:
case 7:
A3Count ++;
break;
case 3:
case 8:
A4Sum += target[i];
A4Count ++;
break;
case 4:
case 9:
if (target[i] > A5Max)
A5Max = target[i];
break;
case 0:
A1Sum += target[i];
break;
}
}
convert(A1Sum, A2Sum, A2F, A3Count, A4Sum, A4Count, A5Max);
}

public static void convert(int a1, int a2, boolean A2F, int a3, int a4, int a4p, int a5) {
StringBuilder stringBuilder = new StringBuilder();
if (a1 == 0) {
stringBuilder.append("N ");
} else {
stringBuilder.append(a1 + " ");
}
if (A2F) {
stringBuilder.append("N ");
} else {
stringBuilder.append(a2 + " ");
}
if (a3 == 0) {
stringBuilder.append("N ");
} else {
stringBuilder.append(a3 + " ");
}
if (a4p == 0) {
stringBuilder.append("N ");
} else {
double result = a4 / (double)a4p;
DecimalFormat decimalFormat = new DecimalFormat("#.0");
stringBuilder.append(decimalFormat.format(result) + " ");
}
if (a5 == 0) {
stringBuilder.append("N");
} else {
stringBuilder.append(a5);
}
System.out.println(stringBuilder.toString());
}

public static void main(String[] args) throws IOException {
main();//真是简洁到让人想哭的调用语句
}