CCF CSP Brush Question Record 25-201809-1 Selling Vegetables (Java)

Question number: 201809-1
Question name: Sell ​​vegetables
time limit: 1.0s
Memory limit: 256.0MB
Problem Description:

Problem Description

  There are n shops selling vegetables on one street, arranged in a row in the order of 1 to n, and these shops all sell one kind of vegetable.
  On the first day, each store set its own price. The shopkeepers hope that the prices of their dishes will be consistent with those of other shops. The next day, each shop will adjust its prices according to the prices of itself and the neighboring shops. Specifically, each store will set the price of the next day's food as the average of the price of the first day's food in its own and neighboring stores (rounded by the tailing method).
  Note that the store numbered 1 has only one adjacent store 2, the store numbered n has only one adjacent store n-1, and the other stores numbered i have two adjacent stores i-1 and i+1 .
  Given the price of food in each store on the first day, please calculate the price of food in each store on the second day.

Input format

  The first line of input contains an integer n, which represents the number of stores.
  The second line contains n integers, which in turn represent the price of the dish on the first day of each store.

Output format

  Output a row, containing n positive integers, indicating the prices of the dishes in each store on the second day in turn.

Sample input

8
4 1 3 1 6 5 17 9

Sample output

2 2 1 3 4 9 10 13

Data size and convention

  For all evaluation use cases, 2 ≤ n ≤ 1000, the price of the food in each store on the first day is a positive integer not exceeding 10,000.

 

import java.util.Scanner;
public class 卖菜 {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		int[] b=new int[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
		}
		b[0]=(a[0]+a[1])/2;
		b[n-1]=(a[n-2]+a[n-1])/2;
		for(int i=1;i<n-1;i++){
			b[i]=(a[i-1]+a[i]+a[i+1])/3;
		}
		for(int i=0;i<n;i++){
			System.out.print(b[i]+" ");
		}
	}

}

 

Guess you like

Origin blog.csdn.net/m0_37483148/article/details/108365077