Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <tuple>
- using namespace std;
- // Перечислимый тип для статуса задачи
- enum class TaskStatus {
- NEW, // новая
- IN_PROGRESS, // в разработке
- TESTING, // на тестировании
- DONE // завершена
- };
- // Объявляем тип-синоним для map<TaskStatus, int>,
- // позволяющего хранить количество задач каждого статуса
- using TasksInfo = map<TaskStatus, int>;
- class TeamTasks {
- public:
- // Получить статистику по статусам задач конкретного разработчика
- const TasksInfo& GetPersonTasksInfo(const string& person) const {
- return name_to_tasks_.at(person);
- };
- // Добавить новую задачу (в статусе NEW) для конкретного разработчитка
- void AddNewTask(const string& person) {
- ++name_to_tasks_[person][TaskStatus::NEW];
- //name_to_tasks_[person][TaskStatus::IN_PROGRESS] = 0;
- //name_to_tasks_[person][TaskStatus::TESTING] = 0;
- //name_to_tasks_[person][TaskStatus::DONE] = 0;
- };
- /*void AddIN_PROGRESSTask(const string& person) {
- ++name_to_tasks_[person][TaskStatus::IN_PROGRESS];
- };
- void AddTESTINGTask(const string& person) {
- ++name_to_tasks_[person][TaskStatus::TESTING];
- };
- void AddDONEask(const string& person) {
- ++name_to_tasks_[person][TaskStatus::DONE];
- };*/
- // Обновить статусы по данному количеству задач конкретного разработчика,
- // подробности см. ниже
- tuple<TasksInfo, TasksInfo> PerformPersonTasks(const string& person, int task_count) {
- TasksInfo untouched_tasks;
- TasksInfo updated_tasks;
- if (name_to_tasks_.count(person) > 0) {
- TasksInfo tasks_to_amount = name_to_tasks_.at(person);
- int sum = static_cast<int>(tasks_to_amount[TaskStatus::NEW]) + static_cast<int>(tasks_to_amount[TaskStatus::IN_PROGRESS]) + static_cast<int>(tasks_to_amount[TaskStatus::TESTING]);
- //cout << sum << endl;
- if (sum < task_count) {
- task_count = sum;
- }
- for (auto [Task_Status, Task_amount] : name_to_tasks_.at(person)) {
- TaskStatus next_Task_Status = static_cast<TaskStatus>(static_cast<int>(Task_Status) + 1);
- if (Task_amount <= task_count) {
- tasks_to_amount[Task_Status] -= min(task_count, Task_amount);
- tasks_to_amount[next_Task_Status] += Task_amount;
- updated_tasks[next_Task_Status] = Task_amount;
- task_count -= Task_amount;
- }
- else {
- tasks_to_amount[Task_Status] -= task_count;
- tasks_to_amount[next_Task_Status] += task_count;
- updated_tasks[next_Task_Status] = task_count;
- untouched_tasks[Task_Status] = name_to_tasks_.at(person).at(Task_Status) - task_count;
- task_count = 0;
- //break;
- }
- if (Task_Status == TaskStatus::TESTING) {
- break;
- }
- }
- for (auto [Task_Status, Task_amount] : tasks_to_amount) {
- name_to_tasks_.at(person)[Task_Status] = Task_amount;
- }
- }
- return tuple(updated_tasks, untouched_tasks);
- };
- private:
- map <string, TasksInfo> name_to_tasks_;
- };
- // Принимаем словарь по значению, чтобы иметь возможность
- // обращаться к отсутствующим ключам с помощью [] и получать 0,
- // не меняя при этом исходный словарь.
- /*void PrintTasksInfo(TasksInfo tasks_info) {
- cout << tasks_info[TaskStatus::NEW] << "/"s
- << tasks_info[TaskStatus::IN_PROGRESS] << "/"s
- << tasks_info[TaskStatus::TESTING] << "/"s
- << tasks_info[TaskStatus::DONE] << ""s << endl;
- }
- int main() {
- TeamTasks tasks;
- tasks.AddNewTask("Ilia");
- for (int i = 0; i < 3; ++i) {
- tasks.AddNewTask("Ivan");
- }
- cout << "Ilia's tasks: ";
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ilia"));
- cout << "Ivan's tasks: ";
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"));
- TasksInfo updated_tasks, untouched_tasks;
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan", 2);
- cout << "Updated Ivan's tasks: ";
- PrintTasksInfo(updated_tasks);
- cout << "Untouched Ivan's tasks: ";
- PrintTasksInfo(untouched_tasks);
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan", 2);
- cout << "Updated Ivan's tasks: ";
- PrintTasksInfo(updated_tasks);
- cout << "Untouched Ivan's tasks: ";
- PrintTasksInfo(untouched_tasks);
- for (int i = 0; i < 5; ++i) {
- tasks.AddNewTask("Ivan"s);
- }
- for (int i = 0; i < 0; ++i) {
- tasks.AddIN_PROGRESSTask("Ivan"s);
- }
- for (int i = 0; i < 0; ++i) {
- tasks.AddTESTINGTask("Ivan"s);
- }
- for (int i = 0; i < 0; ++i) {
- tasks.AddDONEask("Ivan"s);
- }
- cout << "Ivan's tasks before: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- //TasksInfo updated_tasks, untouched_tasks;
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 6);
- cout << "PerformPersonTasks(6)" << endl;
- cout << "Updated Ivan's tasks: "s;
- PrintTasksInfo(updated_tasks);
- cout << "Untouched Ivan's tasks: "s;
- PrintTasksInfo(untouched_tasks);
- cout << "Ivan's tasks after: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- cout << endl;
- for (int i = 0; i < 1200; ++i) {
- tasks.AddNewTask("Ivan"s);
- }
- for (int i = 0; i < 2; ++i) {
- tasks.AddIN_PROGRESSTask("Ivan"s);
- }
- for (int i = 0; i < 2; ++i) {
- tasks.AddTESTINGTask("Ivan"s);
- }
- for (int i = 0; i < 16; ++i) {
- tasks.AddDONEask("Ivan"s);
- }
- cout << "Ivan's tasks before: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 1206);
- cout << "PerformPersonTasks(1206)" << endl;
- cout << "Updated Ivan's tasks: "s;
- PrintTasksInfo(updated_tasks);
- cout << "Untouched Ivan's tasks: "s;
- PrintTasksInfo(untouched_tasks);
- cout << "Ivan's tasks after: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- cout << endl;
- for (int i = 0; i < 1; ++i) {
- tasks.AddNewTask("Ivan"s);
- }
- for (int i = 0; i < 2; ++i) {
- tasks.AddIN_PROGRESSTask("Ivan"s);
- }
- for (int i = 0; i < 3; ++i) {
- tasks.AddTESTINGTask("Ivan"s);
- }
- for (int i = 0; i < 4; ++i) {
- tasks.AddDONEask("Ivan"s);
- }
- cout << "Ivan's tasks before: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 1000);
- cout << "PerformPersonTasks(1000)" << endl;
- cout << "Updated Ivan's tasks: "s;
- PrintTasksInfo(updated_tasks);
- cout << "Untouched Ivan's tasks: "s;
- PrintTasksInfo(untouched_tasks);
- cout << "Ivan's tasks after: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- cout << endl;
- for (int i = 0; i < 1; ++i) {
- tasks.AddNewTask("Ivan"s);
- }
- for (int i = 0; i < 0; ++i) {
- tasks.AddIN_PROGRESSTask("Ivan"s);
- }
- for (int i = 0; i < 0; ++i) {
- tasks.AddTESTINGTask("Ivan"s);
- }
- for (int i = 0; i < 0; ++i) {
- tasks.AddDONEask("Ivan"s);
- }
- cout << "Ivan's tasks before: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 1);
- cout << "PerformPersonTasks(1)" << endl;
- cout << "Updated Ivan's tasks: "s;
- PrintTasksInfo(updated_tasks);
- cout << "Untouched Ivan's tasks: "s;
- PrintTasksInfo(untouched_tasks);
- cout << "Ivan's tasks after: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- cout << endl;
- for (int i = 0; i < 1; ++i) {
- tasks.AddNewTask("Ivan"s);
- }
- for (int i = 0; i < 0; ++i) {
- tasks.AddIN_PROGRESSTask("Ivan"s);
- }
- for (int i = 0; i < 12; ++i) {
- tasks.AddTESTINGTask("Ivan"s);
- }
- for (int i = 0; i < 3; ++i) {
- tasks.AddDONEask("Ivan"s);
- }
- cout << "Ivan's tasks before: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 100);
- cout << "PerformPersonTasks(100)" << endl;
- cout << "Updated Ivan's tasks: "s;
- PrintTasksInfo(updated_tasks);
- cout << "Untouched Ivan's tasks: "s;
- PrintTasksInfo(untouched_tasks);
- cout << "Ivan's tasks after: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- cout << endl;
- for (int i = 0; i < 5; ++i) {
- tasks.AddNewTask("Ivan"s);
- }
- for (int i = 0; i < 5; ++i) {
- tasks.AddIN_PROGRESSTask("Ivan"s);
- }
- for (int i = 0; i < 5; ++i) {
- tasks.AddTESTINGTask("Ivan"s);
- }
- for (int i = 0; i < 0; ++i) {
- tasks.AddDONEask("Ivan"s);
- }
- cout << "Ivan's tasks before: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 10);
- cout << "PerformPersonTasks(10)" << endl;
- cout << "Updated Ivan's tasks: "s;
- PrintTasksInfo(updated_tasks);
- cout << "Untouched Ivan's tasks: "s;
- PrintTasksInfo(untouched_tasks);
- cout << "Ivan's tasks after: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- cout << endl;
- for (int i = 0; i < 5; ++i) {
- tasks.AddNewTask("Ivan"s);
- }
- for (int i = 0; i < 5; ++i) {
- tasks.AddIN_PROGRESSTask("Ivan"s);
- }
- for (int i = 0; i < 0; ++i) {
- tasks.AddTESTINGTask("Ivan"s);
- }
- for (int i = 0; i < 0; ++i) {
- tasks.AddDONEask("Ivan"s);
- }
- cout << "Ivan's tasks before: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 5);
- cout << "PerformPersonTasks(5)" << endl;
- cout << "Updated Ivan's tasks: "s;
- PrintTasksInfo(updated_tasks);
- cout << "Untouched Ivan's tasks: "s;
- PrintTasksInfo(untouched_tasks);
- cout << "Ivan's tasks after: "s;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
- cout << endl;
- }*/
- void PrintTasksInfo(const TasksInfo& tasks_info) {
- if (tasks_info.count(TaskStatus::NEW)) {
- std::cout << "NEW: " << tasks_info.at(TaskStatus::NEW) << " ";
- }
- if (tasks_info.count(TaskStatus::IN_PROGRESS)) {
- std::cout << "IN_PROGRESS: " << tasks_info.at(TaskStatus::IN_PROGRESS) << " ";
- }
- if (tasks_info.count(TaskStatus::TESTING)) {
- std::cout << "TESTING: " << tasks_info.at(TaskStatus::TESTING) << " ";
- }
- if (tasks_info.count(TaskStatus::DONE)) {
- std::cout << "DONE: " << tasks_info.at(TaskStatus::DONE) << " ";
- }
- }
- void PrintTasksInfo(const TasksInfo& updated_tasks, const TasksInfo& untouched_tasks) {
- std::cout << "Updated: [";
- PrintTasksInfo(updated_tasks);
- std::cout << "] ";
- std::cout << "Untouched: [";
- PrintTasksInfo(untouched_tasks);
- std::cout << "] ";
- std::cout << std::endl;
- }
- int main() {
- TeamTasks tasks;
- TasksInfo updated_tasks;
- TasksInfo untouched_tasks;
- // TEST 3
- std::cout << "\nLisa" << std::endl;
- for (auto i = 0; i < 5; ++i) {
- tasks.AddNewTask("Lisa");
- }
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 5);
- PrintTasksInfo(updated_tasks, untouched_tasks); // [{"IN_PROGRESS": 5}, {}]
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 5);
- PrintTasksInfo(updated_tasks, untouched_tasks); // [{"TESTING": 5}, {}]
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 1);
- PrintTasksInfo(updated_tasks, untouched_tasks); // [{"DONE": 1}, {"TESTING": 4}]
- for (auto i = 0; i < 5; ++i) {
- tasks.AddNewTask("Lisa");
- }
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 2);
- PrintTasksInfo(updated_tasks, untouched_tasks); // [{"IN_PROGRESS": 2}, {"NEW": 3, "TESTING": 4}]
- PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa")); // {"NEW": 3, "IN_PROGRESS": 2, "TESTING": 4, "DONE": 1}
- std::cout << std::endl;
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 4);
- PrintTasksInfo(updated_tasks, untouched_tasks); // [{"IN_PROGRESS": 3, "TESTING": 1}, {"IN_PROGRESS": 1, "TESTING": 4}]
- PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa")); // {"IN_PROGRESS": 4, "TESTING": 5, "DONE": 1}
- std::cout << std::endl;
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 5);
- PrintTasksInfo(updated_tasks, untouched_tasks); // [{"TESTING": 4, "DONE": 1}, {"TESTING": 4}]
- PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa")); // {"TESTING": 8, "DONE": 2}
- std::cout << std::endl;
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 10);
- PrintTasksInfo(updated_tasks, untouched_tasks); // [{"DONE": 8}, {}]
- PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa")); // {"DONE": 10}
- std::cout << std::endl;
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 10);
- PrintTasksInfo(updated_tasks, untouched_tasks); // [{}, {}]
- PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa")); // {"DONE": 10}
- std::cout << std::endl;
- tasks.AddNewTask("Lisa");
- PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa")); // {"NEW": 1, "DONE": 10}
- std::cout << std::endl;
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 2);
- PrintTasksInfo(updated_tasks, untouched_tasks); // [{"IN_PROGRESS": 1}, {}]
- PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa")); // {"IN_PROGRESS": 1, "DONE": 10}
- std::cout << std::endl;
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Bob", 3);
- PrintTasksInfo(updated_tasks, untouched_tasks); // [{}, {}]
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement