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

C++ 实现吊桥木头摆放数量及总宽度计算

```cpp #include <iostream> using namespace std; int main() { int n; cin >> n; int count = 0; // 放到吊桥上的木头数量 int totalWidth = 0; // 放到吊桥上的木头总宽度 for (int i = 0; i < n; i++) { int length, width; cin >> length >> width; // 判断木头长度是否满足条件且总宽度是否未达到10 if (length >= 5 && totalWidth + width <= 10) { count++; totalWidth += width; } // 如果总宽度达到10,停止摆放 if (totalWidth == 10) { break; } } cout << count << " " << totalWidth << endl; return 0; } ``` ######[AI问答 | 223点数解答 | 2026-04-18 19:40:39]

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