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

最熱的一天

#012入門if (t > best)約 3 分鐘

旅行這一週每天記了一個氣溫。寫 hottest(temps),返回最高的那個。至少有一天,氣溫可能是負的。

示例
hottest({21, 25, 19})→25
hottest({18, 18, 22, 20})→22
函式int hottest(const vector<int> &temps)
main.cpp
#include <vector>
using namespace std;

int hottest(const vector<int> &temps) {
    int best = temps[0];
    for (int t : temps) {
        // 在這裡寫:t 比 best 高,就換成 t
    }
    return best;
}
Ctrl + Enter 也能執行
結果

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