注意边界0和n-1

#include<bits/stdc++.h>
using namespace std;
const int maxn=100;
int arr[maxn];
int main(){
	int n;
	while(cin>>n){
		vector<int> ans;
		for(int i=0; i < n; i++){
			cin>>arr[i];
		}
		if(arr[0] > arr[1] ||arr[0] < arr[1]) ans.push_back(0);
		for(int i = 1; i < n-1; i++){
			if(arr[i] > arr[i-1] && arr[i] > arr[i+1]) ans.push_back(i);
			if(arr[i] < arr[i-1] && arr[i] < arr[i+1]) ans.push_back(i);
		}
		if(arr[n-1] > arr[n-2] ||arr[n-1] < arr[n-2]) ans.push_back(n-1);
		for(int i=0; i < ans.size(); i++){
			cout<<ans[i];
			if(i!=ans.size()-1) cout<<" ";
			else cout<<endl;
		}
	}
	
	
	
	return 0;
}