Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int N = 110;
- int n, a[N];
- int main(){
- cin >> n;
- for (int i = 1; i <= n; i ++) {
- cin >> a[i];
- }
- for (int j = 1; j < n; j ++) {
- // 每轮 (j, n)
- int minIndex = j;
- for(int i = j + 1; i <= n; i ++) {
- if (a[minIndex] > a[i]) minIndex = i;
- }
- swap(a[minIndex], a[j]);
- for (int i = 1; i <= n; i ++) cout << a[i] << ' ';
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement