Advertisement
smatskevich

Min2

Feb 27th, 2021
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main() {
  4.   int n = 0;
  5.   std::cin >> n;
  6.  
  7.   if (n <= 0) {
  8.     std::cout << "ERROR: An array is empty.";
  9.     return 0;
  10.   }
  11.  
  12.   int x = 0;
  13.   std::cin >> x;
  14.  
  15.   int cur_min_index = 0;
  16.   int cur_min = x;
  17.   for (int i = 1; i < n; ++i) {
  18.     std::cin >> x;
  19.     if (x <= cur_min) {  // Последнее вхождение минимального элемента
  20.       cur_min = x;
  21.       cur_min_index = i;
  22.     }
  23.   }
  24.   std::cout << cur_min_index;
  25.   return 0;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement