Advertisement
adrienbrody2011

Second minimum (version 2)

Aug 19th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.     int a[100];
  9.     for (int i = 0; i < n; i++) {
  10.         cin >> a[i];
  11.     }
  12.     int min_number = a[0];
  13.     int min_number_id = 0;
  14.     for (int i = 1; i < n; i++) {
  15.         if (min_number > a[i]) {
  16.             min_number = a[i];
  17.             min_number_id = i;
  18.         }
  19.     }
  20.     a[min_number_id] = 100000;
  21.     int min_number_2 = a[0];
  22.     for (int i = 1; i < n; i++) {
  23.         if (min_number_2 > a[i]) {
  24.             min_number_2 = a[i];
  25.         }
  26.     }
  27.     cout << min_number_2 << "\n";
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement