n, m = map(int, input().split()) max_score = -1 max_info = "" for _ in range(n): line = input().split() name, scores = line[0], list(map(int, line[1:])) total_score = sum(scores) if total_score > max_score: max_score = total_score max_info = line print(max_info[0], end=' ') print(*max_info[1:], max_score) 改c++
时间: 2024-04-07 15:33:24 浏览: 141
turbocodermax-log.rar_LOG-MAP译码_Max Log MAP _Max-Log-Map_log map
5星 · 资源好评率100%
以下是将上述Python代码转换为C++的等效:
```cpp
#include <iostream>
#include <vector>
#include <sstreamusing namespace std;
int main() int n, m;
cin >> >> m;
int max_score = -1;
vector<string> max_info;
for (int i = 0; i < n; i++) {
string line;
getline(cin.ignore(), line);
stringstream ss(line);
string name;
ss >> name;
vector<int> scores(m);
for (int j = 0; j < m; j++) {
ss >> scores[j];
}
int total_score = 0;
for (int score : scores) {
total_score += score;
}
if (total_score > max_score) {
max_score = total_score;
max_info = {name};
max_info.insert(max_info.end(), scores.begin(), scores.end());
}
}
cout << max_info[0] << " ";
for (int i = 1; i <= m; i++) {
cout << max_info[i] << " ";
}
cout << max_score << endl;
return 0;
}
```
这段C++代码实现了与上述Python代码相同的逻辑。它使用了`std::vector`来保存最高分人的信息,并使用`std::stringstream`来解析输入的每一行。最后,它输出最高分人的姓名、成绩和总分。
希望对你有帮助!如果有任何其他问题,请随时提问。
阅读全文