2559 - 选择排序
输入n个数,从小到大输出。(使用选择排序)
Input
Output
Examples
Input
Output
Solution 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; }