一个循环数组找相邻最小值
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n,a0,alast,anow;
int index,minimal=9999;
cin>>n;
cin>>a0;
alast=a0;
for(int i=1;i<n;i++)
{
cin>>anow;
if(abs(anow-alast)<minimal)
{
minimal=abs(anow-alast);
index=i+1;
}
alast=anow;
}
if(abs(a0-anow)<minimal) cout<<n<<" 1";
else cout<<index-1<<" "<<index;
return 0;
}