Advertisement
wym1111

Untitled

Dec 2nd, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 110;
  5. int n, a[N];
  6.  
  7. int main(){
  8. cin >> n;
  9. for (int i = 1; i <= n; i ++) {
  10. cin >> a[i];
  11. }
  12. for (int j = 1; j < n; j ++) {
  13. // 每轮 (j, n)
  14. int minIndex = j;
  15. for(int i = j + 1; i <= n; i ++) {
  16. if (a[minIndex] > a[i]) minIndex = i;
  17. }
  18. swap(a[minIndex], a[j]);
  19. for (int i = 1; i <= n; i ++) cout << a[i] << ' ';
  20. cout << endl;
  21. }
  22. return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement