一直数组上溢,本来想说是不是给分配的内存少,超过30个的数组要分开几次存储,结果!只要把数组定义语句放在while里面就行了,写了好久。。
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) { // 注意 while 处理多个 case
int *a = new int[n];
int i;
for (i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < n; i++){
if (i == 0 && a[i] != a[i+1]) cout<<i<<" ";
else if (a[i] > a[i+1] && a[i] > a[i-1]) cout<<i<<" ";
else if (a[i] < a[i+1] && a[i] < a[i-1]) cout<<i<<" ";
else if (i == n-1 && a[i-1] != a[i]) cout<<i<<" ";
}
cout<<endl;
}
}
// 64 位输出请用 printf("%lld")

京公网安备 11010502036488号