CCF CSP Brush Question Record 14-201609-1 Maximum Fluctuation (Java)

Question number: 201609-1
Question name: Maximum fluctuation
time limit: 1.0s
Memory limit: 256.0MB
Problem Description:

Problem Description

  Xiao Ming is using the volatility of stocks to study stocks. Xiao Ming got the daily closing price of a stock. He wanted to know the maximum fluctuation value of this stock for several consecutive days, that is, the absolute value of the difference between the closing price of a certain day and the closing price of the previous day during these few days how many.

Input format

  The first line of input contains an integer n , which represents the number of consecutive days for the closing price that Xiao Ming received.
  The second line contains n positive integers, which in turn represent the daily closing price.

Output format

  Output an integer that represents the maximum fluctuation value of this stock in n days.

Sample input

6
2 5 5 7 3 5

Sample output

4

Sample description

  The fluctuation between the fourth day and the fifth day is the largest, and the fluctuation value is |3-7|=4.

Evaluation use case scale and conventions

  For all evaluation use cases, 2 ≤  n  ≤ 1000. The daily price of the stock is an integer between 1 and 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+1];
		for(int i=1;i<=n;i++){
			a[i]=sc.nextInt();
		}
		int res=0;
		for(int i=1;i<n;i++){
			int k=Math.abs(a[i]-a[i+1]);
			if(k>res){
				res=k;
			}
		}
		System.out.println(res);
	}

}

 

Guess you like

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