CSP2017-12
CSP201712-1 最小差值
1 // 2 // main.cpp 3 // CSP201712-1 最小差值 4 // 5 // Created by sylvia on 2021/11/6. 6 // Copyright © 2021 apple. All rights reserved. 7 // 8 9 #include <iostream> 10 #include <algorithm> 11 #include <math.h> 12 using namespace std; 13 int n,a[1000+5],minn=100000; 14 int main(){ 15 cin>>n; 16 for (int i=0;i<n;i++){ 17 cin>>a[i]; 18 } 19 sort(a,a+n); 20 for (int i=0;i<n-1;i++){ 21 minn=min(minn,abs(a[i]-a[i+1])); 22 } 23 cout<<minn<<endl; 24 return 0; 25 }