面包店的面包都要涨 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;
}
写好了先点「运行」试试示例,没问题再点「提交」。