Created
October 9, 2019 16:25
-
-
Save surinoel/0d9e631cb310ffbaeb2efa970038eb5a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <climits> | |
#include <iostream> | |
using namespace std; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int n; | |
cin >> n; | |
vector<int> a(n); | |
for (int i = 0; i < n; i++) { | |
cin >> a[i]; | |
} | |
for (int i = 0; i < n - 1; i++) { | |
int minv = INT_MAX; | |
int index = i; | |
for (int j = i; j < n; j++) { | |
if (minv > a[j]) { | |
index = j; | |
minv = a[j]; | |
} | |
} | |
int tmp = a[i]; | |
a[i] = a[index]; | |
a[index] = tmp; | |
} | |
for (int i = 0; i < n; i++) { | |
cout << a[i] << ' '; | |
} | |
cout << '\n'; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment