版权声明:转载请标明出处 https://blog.csdn.net/qq_29110265/article/details/83536715
问 题 描述 : |
问题描述 在一条街上有n个卖菜的商店,按1至n的顺序排成一排,这些商店都卖一种蔬菜。 输入格式 输入的第一行包含一个整数n,表示商店的数量。 输出格式 输出一行,包含n个正整数,依次表示每个商店第二天的菜价。 样例输入 8 样例输出 2 2 1 3 4 9 10 13 数据规模和约定 对于所有评测用例,2 ≤ n ≤ 1000,第一天每个商店的菜价为不超过10000的正整数。 |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Scanner sc=new Scanner(System.in);
int num=sc.nextInt();
int price[]=new int[num];
for(int i=0;i<num;i++)
{
price[i]=sc.nextInt();
}
for(int t=0;t<num;t++)
{
if(t==0)
{
System.out.print((price[0]+price[1])/2+" ");//第一家店
}
else if(t==num-1)
{
System.out.print((price[t]+price[t-1])/2);//最后一家店
}
else
System.out.print((price[t-1]+price[t]+price[t+1])/3+" ");//其他店
}
}
}