201609-1 Maximum fluctuation

问题描述

试题号: 201609-1
试题名称: maximum fluctuation
时间限制: 1.0s
Memory limit: 256.0MB
问题Description:

问题描述

小明 is using stock volatility to study stocks. Xiao Ming got the price of a stock at the close of the day. He wants to know the maximum volatility of the stock for several consecutive days, that is, the absolute difference between the closing price of the day and the closing price of the previous day. how many.

Input format

The first line of the input contains an integer n, which indicates the number of consecutive days that Xiaoming received the closing price. The second line contains n a positive integer, which in turn represents the daily closing price.

output format

outputs an integer indicating the maximum fluctuation of the stock in this n day.

样样输入

6 2 5 5 7 3 5

样样出

4

样例说明

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

Evaluation use case size and agreement

For all evaluation use cases, 2 ≤n ≤ 1000. The price of a stock per day is an integer between 1 and 10,000.

码展示:

#include <iostream>
#include<cmath>
#include <algorithm>
#include<vector> 
using namespace std;
int main() {
   	int n,max=0;
   	cin>>n;
   	vector<int>vis;
   	int k;
   	for(int i=0;i<n;i++){
   			scanf("%d",&k);
   			vis.push_back(k);
	   }
   	for(int i=0;i<n-1;i++){
   		if((int)fabs(vis[i+1]-vis[i])>max)
   			max=(int)fabs(vis[i+1]-vis[i]);
	   }
	   cout<<max;
    return 0;
}