麵包店的麵包都要漲 extra 元。寫 raise_all(prices, extra):用範圍 for 把 prices 裡每個價錢都加上 extra。沒有面包(空的)就什麼都不變。
new_prices({10, 12, 8}, 2)→[12, 14, 10]new_prices({}, 5)→[]vector<int> new_prices(vector<int> prices, int extra)#include <vector>
using namespace std;
void raise_all(vector<int> &prices, int extra) {
// 在這裡寫:每個價錢加上 extra
}
vector<int> new_prices(vector<int> prices, int extra) {
raise_all(prices, extra);
return prices;
}
寫好了先點「執行」試試示例,沒問題再點「提交」。