这段代码为什么会报语法错误:int miceAndCheese(vector<int>& reward1, vector<int>& reward2, int k) { vector<pair<int, int>>v; for(int i = 0; i < reward1.size(); i++) { v.push_back(make_pair(reward1[i], reward2[i])); } sort(v.begin(), v.end(), greater<int>()); int ans = 0; for(int i = 0; i < v.size(); i++) cout << v[i].first << " " << v[i].second << endl; return ans; } };
时间: 2024-03-17 08:47:15 浏览: 52
robotmoving.rar_finaltai_强化学习_强化学习代码
这段代码会报语法错误是因为有一个多余的 "}; "在代码的末尾,应该将它删除。代码的正确形式如下:
```
int miceAndCheese(vector<int>& reward1, vector<int>& reward2, int k) {
vector<pair<int, int>>v;
for(int i = 0; i < reward1.size(); i++) {
v.push_back(make_pair(reward1[i], reward2[i]));
}
sort(v.begin(), v.end(), greater<int>());
int ans = 0;
for(int i = 0; i < v.size(); i++) cout << v[i].first << " " << v[i].second << endl;
return ans;
}
```
阅读全文