201809-1 卖菜 Java

思路:
需要两个数组,一个保存原始数据

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int shop[] = new int[n];//保存原始数据
        int store[] = new int[n];
        for(int i=0;i<n;i++) {
            shop[i] = sc.nextInt();
        }
        store[0] = (shop[0]+shop[1])/2;
        store[n-1] = (shop[n-2]+shop[n-1])/2;
        for(int j=1;j<n-1;j++) {
            store[j] = (shop[j-1]+shop[j]+shop[j+1])/3;
        }
        sc.close();
        for(int k=0;k<n;k++) {
            System.out.print(store[k] + " ");
        }
    }

}

猜你喜欢

转载自www.cnblogs.com/yu-jiawei/p/12371307.html