題意
給 n 個整數,將 n 個數字從小到大排序好輸出。
解題方法
利用 #include <algorithm> 裡的 sort 完成這題
複雜度: O(nlogn)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
while(cin >> n){
vector <int> a(n);
for(int &x : a) cin >> x;
sort(a.begin(), a.end());
for(int i = 0;i < n;i++){
cout << a[i] << " \n"[i == n-1];
}
}
}
發表迴響