Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created October 9, 2019 16:25
Show Gist options
  • Save surinoel/0d9e631cb310ffbaeb2efa970038eb5a to your computer and use it in GitHub Desktop.
Save surinoel/0d9e631cb310ffbaeb2efa970038eb5a to your computer and use it in GitHub Desktop.
#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