1 solutions

  • 0
    @ 2025-11-5 15:19:09

    C++ :

    #include <iostream>
    using namespace std;
    const int N = 1e5 + 10;
    int a[N];
    int n;
    int main(){
        cin >> n;
        for (int i = 0; i < n; i ++) cin >> a[i];
        for (int i = 0; i < n; i ++){
            int k = i;
            for (int j = i; j < n; j ++)
                if (a[j] < a[k]) k = j;
            swap(a[i], a[k]);
        }
        for (int i = 0; i < n; i ++) cout << a[i] << ' ';
        cout << endl;
        return 0;
    }
    

    Pascal :

    var
      i,j,n,t,min,pos:integer;
      a:array[1..100] of integer;
    begin
       readln(n);
    
       for i:=1 to n do read(a[i]);
    
       for i:=1 to n-1 do
         begin
           min:=a[i]; pos:=i;
           for j:=i+1 to n do
             if a[j]<min then
             begin
               min:=a[j];
               pos:=j;
             end;
    
            t:=a[i]; a[i]:=a[pos]; a[pos]:=t;
        end;
      for i:=1 to n do
       write(a[i],' ');
    end.
    
    • 1

    Information

    ID
    16648
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By