CCF 201604-1 Breakpoint calculation (full mark 100)

This question is very simple and does not involve any algorithms.

#include<iostream>

using namespace std;

int main()
{
    
    
	int n, a[1000] = {
    
     0 };
	cin >> n;
	for (int i = 0; i < n; i++) {
    
    
		cin >> a[i];
	}
	int count = 0;
	for (int i = 1; i < n-1; i++) {
    
    
		if ((a[i] > a[i - 1] && a[i] > a[i + 1]) || (a[i]<a[i - 1] && a[i]<a[i + 1]))  
			count++;
		
	}
	cout << count << endl;

	system("pause");
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_27538633/article/details/105720864