酷代码 AI
菜单
服务商

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问答 | 196点数解答 | 2026-04-06 21:27:28]

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