歡迎加入我的 Discord 群組與我討論程式相關的問題!

Posted on 

 by 

 in 

Zerojudge a104. 排序

評分:1 分,滿分為 5。

題目連結

題意

給 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];
        }
    }
}

輸入輸出參考資料

發表迴響

Blog at WordPress.com.

%d 位部落客按了讚: