方法一:超时(80分)
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] a = new int[n];
int[] b = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scanner.nextInt();
}
for (int i = 0; i < n; i++) {
if (i == 0){
b[i] = (a[i]+a[i+1])/2;
}else if (i == n-1){
b[i] = (a[i-1]+a[i])/2;
}else {
b[i] = (a[i-1]+a[i]+a[i+1])/3;
}
}
for (int c:b
) {
System.out.print(c+" ");
}
}
}
方法二:(100)分
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] a = new int[n];
int[] b = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scanner.nextInt();
if (i == 1){
b[i-1] = (a[i]+a[i-1])/2;
}else if(i != 0) {
b[i-1] = (a[i-2]+a[i-1]+a[i])/3;
}
}
b[n-1] = (a[n-1]+a[n-2])/2;
for (int c:b
) {
System.out.print(c+" ");
}
}
}