題目:
代碼:
import java.util.Scanner;
public class SellVeg {
public static void main(String[] args) {
int n;
int[] price;
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
price = new int[n+1];
for(int i=1;i<=n;i++) {
price[i] = scan.nextInt();
}
sv(price);
}
public static void sv(int[] price) {
int[] secondPrice = new int[price.length];
for(int i=1;i<=price.length-1;i++) {
if(i==1)
secondPrice[i] = (price[i]+price[i+1])/2;
else if(i==price.length-1)
secondPrice[i] = (price[i]+price[i-1])/2;
else
secondPrice[i] = (price[i+1]+price[i]+price[i-1])/3;
}
for(int j=1;j<=secondPrice.length-1;j++) {
System.out.print(secondPrice[j]+" ");
}
}
}
主類名稱改為Main