Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. using namespace std;
  5. int main() {
  6. long long n , r;
  7. long long a[100];
  8.    int iMin=1000, firstN = 0, secondN=0;
  9. long long im = 0 , ipm =0;
  10. cin >> n;
  11. for (int i = 0; i < n; i++)
  12.   cin >> a[i];
  13. long long m = a[0];
  14. long long am = a[0];
  15.   for(int i = 0; i < n;i++){
  16.       ipm= i ;
  17.         for(int j = i+1; j < n;j++){
  18.             im = j ;
  19.             if(std::abs(a[i]-a[j]) < iMin){
  20.                 iMin=std::abs(a[i]-a[j]);
  21.                 firstN = a[i];
  22.                 secondN = a[j];
  23.  
  24.             }
  25.         }
  26.   }
  27.     std::cout  << firstN << "   " << secondN<< "   " << im<<  "   "<< ipm;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement