酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

用c++写出以下题目的程序 题目描述 Alan 要参加若恩的语法周赛了,他通过提前占卜算出来了每道题的 30,60,100 分,分别需要花费的时间。 第一题如果你分配了 x 1​分钟 当 x 1​<a 1​时你可以取得 0 分 当 a 1​≤x 1​<a 2​时你可以取得 30 分 当 a 2​≤x 1​<a 3​时你可以取得 60 分 当 a 3​≤x 1​时你可以取得 100 分 第二题如果你分配了 x 2​分钟 当 x 2​<b 1​时你可以取得 0 分 当 b 1​≤x 2​<b 2​时你可以取得 30 分 当 b 2​≤x 2​<b 3​时你可以取得 60 分 当 b 3​≤x 2​时你可以取得 100 分 第三题如果你分配了 x 3​分钟 当 x 3​<c 1​时你可以取得 0 分 当 c 1​≤x 3​<c 2​时你可以取得 30 分 当 c 2​≤x 3​<c 3​时你可以取得 60 分 当 c 3​≤x 3​时你可以取得 100 分 第四题如果你分配了 x 4​分钟 当 x 4​<d 1​时你可以取得 0 分 当 d 1​≤x 4​<d 2​时你可以取得 30 分

```cpp #include <iostream> #include <vector> int main() { std::vector<int> a(3), b(3), c(3), d(3); std::cin >> a[0] >> a[1] >> a[2]; std::cin >> b[0] >> b[1] >> b[2]; std::cin >> c[0] >> c[1] >> c[2]; std::cin >> d[0] >> d[1] >> d[2]; int maxScore = 0; int x1 = 0, x2 = 0, x3 = 0, x4 = 0; for (int i1 = 0; i1 <= 120; i1++) { for (int i2 = 0; i2 <= 120 - i1; i2++) { for (int i3 = 0; i3 <= 120 - i1 - i2; i3++) { int i4 = 120 - i1 - i2 - i3; int score = 0; if (i1 >= a[2]) score += 100; else if (i1 >= a[1] && i1 < a[2]) score += 60; else if (i1 >= a[0] && i1 < a[1]) score += 30; if (i2 >= b[2]) score += 100; else if (i2 >= b[1] && i2 < b[2]) score += 60; else if (i2 >= b[0] && i2 < b[1]) score += 30; if (i3 >= c[2]) score += 100; else if (i3 >= c[1] && i3 < c[2]) score += 60; else if (i3 >= c[0] && i3 < c[1]) score += 30; if (i4 >= d[2]) score += 100; else if (i4 >= d[1] && i4 < d[2]) score += 60; else if (i4 >= d[0] && i4 < d[1]) score += 30; if (score > maxScore) { maxScore = score; x1 = i1; x2 = i2; x3 = i3; x4 = i4; } } } } std::cout << x1 << " " << x2 << " " << x3 << " " << x4 << std::endl; return 0; } // 注意 1:输入数据时要确保数据的正确性和合法性。 // 注意 2:循环的边界条件要仔细检查,避免出现越界错误。 // 注意 3:对于得分的计算逻辑要清晰明确,确保能正确计算每种情况的得分。 ``` [2025-03-29 14:02:19 | AI写代码神器 | 708点数解答]

相关提问