Description n Input The first line contains integer Output Output two integers — indexes of Sample Input
Input
5 10 12 13 15 10
Output
5 1
Input
4 10 20 30 40
Output
1 2 |
题目要求:求站成一圈的士兵相邻身高差最小的两士兵的编号(有多对的话取找到的第一队)
#include<iostream> #include<cmath> using namespace std; int main() { int n,a[1000],i,j,min; while(scanf("%d",&n)!=EOF) { min=10001; cin>>a[1]; for(i=2;i<=n;i++) { cin>>a[i]; if(abs(a[i]-a[i-1])<min) { min=abs(a[i]-a[i-1]); j=i; } } if(abs(a[n]-a[1])<min) cout<<n<<" 1"<<endl; else cout<<j-1<<" "<<j<<endl; } return 0; }