Advertisement
wym1111

Untitled

Dec 2nd, 2023
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 110;
  5.  
  6. int n;
  7. int h[N], id[N];
  8.  
  9. struct Student {
  10.     int h, id;
  11. } student[N];
  12.  
  13. int main(){
  14.     cin >> n;
  15.     for (int i = 1; i <= n; i ++) {
  16.         cin >> h[i];
  17.         id[i] = i;
  18.     }
  19.     for (int j = 1; j < n; j ++) {
  20.         // (j, n)
  21.         int minIndex = j;
  22.         for (int i = j; i <= n; i ++) {
  23.             if (h[minIndex] > h[i]) {
  24.                 minIndex = i;
  25.             }
  26.         }
  27.         swap(h[minIndex], h[j]);
  28.         swap(id[minIndex], id[j]);
  29.         for (int i = 1; i <= n; i ++) {
  30.             cout << id[i] << ' ';
  31.         }
  32.         cout << endl;
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement