写 sum_all(v),把 vector 里所有的数加起来返回。空的就是 0。
sum_all({3, 4, 5})→12sum_all({})→0int sum_all(const vector<int> &v)#include <vector>
using namespace std;
int sum_all(const vector<int> &v) {
int total = 0;
// 在这里写:用范围 for 把每个数加到 total
return total;
}
写好了先点「运行」试试示例,没问题再点「提交」。