1 条题解
-
0
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
信息
- ID
- 457
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者