酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

C++实现计算分组乘船最重一组重量和

```cpp #include <iostream> #include <algorithm> using namespace std; int main() { int n; cin >> n; int weights[100]; for (int i = 0; i < n; i++) { cin >> weights[i]; } // 对体重数组进行从小到大排序 sort(weights, weights + n); int maxWeight = 0; // 计算每一组的重量和,并找出最大值 for (int i = 0; i < n / 2; i++) { int currentWeight = weights[i] + weights[n - i - 1]; if (currentWeight > maxWeight) { maxWeight = currentWeight; } } cout << maxWeight << endl; return 0; } ``` ######[AI问答 | 209点数解答 | 2026-05-10 20:33:35]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]