CCF maximum fluctuation (full score code + problem-solving idea: violent simulation) 201609-1

problem solving ideas

Find the absolute value of the difference between two adjacent numbers
Traverse from the second number to the last number
Calculate the absolute value of the difference between a[i] and a[i- 1] to get the final answer


Code

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>

using namespace std;

const int N = 1010;

int a[N];

int main()
{
    
    
    int n;
    cin >> n;

    for (int i = 1; i <= n; i ++) cin >> a[i];
    int res = 0;
    for (int i = 2; i <= n; i ++) res = max(res, abs(a[i] - a[i - 1]));
    cout << res;
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_51800570/article/details/129151106