Kodewick
開始學 →
入門←→0 / 86

班級合照

#047入門sort(begin, end)約 2 分鐘

拍班級合照,大家從矮到高站一排。寫 photo_line(heights):用 <algorithm> 裡的 sort 把身高從小到大排好再返回。

示例
photo_line({150, 138, 145})→[138, 145, 150]
photo_line({})→[]
函式vector<int> photo_line(vector<int> heights)
main.cpp
#include <algorithm>
#include <vector>
using namespace std;

vector<int> photo_line(vector<int> heights) {
    // 在這裡寫:把 heights 排好
    return heights;
}
Ctrl + Enter 也能執行
結果

寫好了先點「執行」試試示例,沒問題再點「提交」。