def plan(day, task): if day > task: return -1 else: listtask = [] if day == task: for i…
- User
def plan(day, task): if day > task: return -1 else: list_task = [] if day == task: for i in range(day): list_task.append(1) else: if task % day == 0: add = task // day for i in range(day): list_task.append(add) else: add = task // day for i in range(0,day-1): list_task.append(add)
list_task.append(add+1) return list_taska = int(input()) for i in range(a): day, task = map(int, input().split()) new = plan(day, task) if new != -1: print(*new) else: print(new)
convert to c++
- Assistant
Below is the equivalent C++ code for the provided Python function and script. This C++ code will read multiple test cases, calculate the task distribution over the given days, and print the results similarly to the Python script.
#include <iostream> #include <vector> std::vector<int> plan(int day, int task) { std::vector<int> list_task; if (day > task) { return {-1}; } if (day == task) { list_task.resize(day, 1); } else { int add = task / day; if (task % day == 0) { list_task.resize(day, add); } else { for (int i = 0; i < day - 1; ++i) { list_task.push_back(add); } list_task.push_back(add + 1); } } return list_task; } int main() { int a; std::cin >> a; for (int i = 0; i < a; ++i) { int day, task; std::cin >> day >> task; std::vector<int> result = plan(day, task); if (!result.empty() && result[0] != -1) { for (size_t j = 0; j < result.size(); ++j) { std::cout << result[j]; if (j < result.size() - 1) { std::cout << " "; } } std::cout << std::endl; } else { std::cout << -1 << std::endl; } } return 0; }