Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <tuple>
- #include <vector>
- using namespace std;
- // Перечислимый тип для статуса задачи
- enum class TaskStatus {
- NEW, // новая
- IN_PROGRESS, // в разработке
- TESTING, // на тестировании
- DONE // завершена
- };
- // Объявляем тип-синоним для map<TaskStatus, int>,
- // позволяющего хранить количество задач каждого статуса
- using TasksInfo = map<TaskStatus, int>;
- TaskStatus GetNextStatus(TaskStatus status){
- TaskStatus next_status;
- switch(status){
- case TaskStatus::NEW:
- next_status = TaskStatus::IN_PROGRESS;
- break;
- case TaskStatus::IN_PROGRESS:
- next_status = TaskStatus::TESTING;
- break;
- case TaskStatus::TESTING:
- next_status = TaskStatus::DONE;
- break;
- default:
- next_status = TaskStatus::DONE;
- break;
- }
- return next_status;
- }
- class TeamTasks {
- public:
- map<string, TasksInfo> person_tasks_info_;
- // Получить статистику по статусам задач конкретного разработчика
- const TasksInfo& GetPersonTasksInfo(const string& person) const{
- auto ptr = person_tasks_info_.find(person);
- //if (ptr == person_tasks_info_.end()) return;
- return ptr->second;
- }
- // Добавить новую задачу (в статусе NEW) для конкретного разработчитка
- void AddNewTask(const string& person){
- ++person_tasks_info_[person][TaskStatus::NEW];
- };
- // task_count == 40
- // new 2 -> 0 -> 0 -> 0
- // 2 -> 0 -> 0
- // Обновить статусы по данному количеству задач конкретного разработчика,
- // подробности см. ниже
- tuple<TasksInfo, TasksInfo> PerformPersonTasks(const string& person, int task_count){
- TasksInfo updated_tasks, untouched_tasks;
- if (person_tasks_info_.count(person) == 0) return {updated_tasks, untouched_tasks};
- for (auto [status, count] : person_tasks_info_[person]){
- if (status == TaskStatus::DONE){
- continue;;
- }
- if (task_count == 0){
- untouched_tasks[status] = count;
- }
- else if (count <= task_count){
- updated_tasks[GetNextStatus(status)] = count;
- task_count -= count;
- }
- else{
- updated_tasks[GetNextStatus(status)] = task_count;
- untouched_tasks[status] = count - task_count;
- task_count = 0;
- }
- }
- person_tasks_info_[person][TaskStatus::NEW] = untouched_tasks[TaskStatus::NEW];
- for (auto [status, count] : updated_tasks){
- TaskStatus next_status = GetNextStatus(status);
- person_tasks_info_[person][status] += updated_tasks[status] - updated_tasks[next_status];
- if (person_tasks_info_[person][status] == 0){
- person_tasks_info_[person].erase(status);
- }
- }
- return {updated_tasks, untouched_tasks};
- }
- };
- // Принимаем словарь по значению, чтобы иметь возможность
- // обращаться к отсутствующим ключам с помощью [] и получать 0,
- // не меняя при этом исходный словарь.
- void PrintTasksInfo(TasksInfo tasks_info) {
- cout << tasks_info[TaskStatus::NEW] << " new tasks"s
- << ", "s << tasks_info[TaskStatus::IN_PROGRESS] << " tasks in progress"s
- << ", "s << tasks_info[TaskStatus::TESTING] << " tasks are being tested"s
- << ", "s << tasks_info[TaskStatus::DONE] << " tasks are done"s << endl;
- }
- int main() {
- TeamTasks tasks;
- TasksInfo updated_tasks, untouched_tasks;
- tasks.person_tasks_info_["Ilia"s][TaskStatus::NEW] = 1;
- //tasks.person_tasks_info_["Ilia"s][TaskStatus::IN_PROGRESS] = 2;
- //tasks.person_tasks_info_["Ilia"s][TaskStatus::TESTING] = 4;
- tasks.person_tasks_info_["Ilia"s][TaskStatus::DONE] = 1;
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ilia"s));
- /*
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 2);
- cout << "Updated Ivan's tasks: "s;
- PrintTasksInfo(updated_tasks);
- cout << "Untouched Ivan's tasks: "s;
- PrintTasksInfo(untouched_tasks);
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 100);
- cout << "Updated Ivan's tasks: "s;
- PrintTasksInfo(updated_tasks);
- cout << "Untouched Ivan's tasks: "s;
- PrintTasksInfo(untouched_tasks);
- */
- tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ilia"s, 1000);
- cout << "Updated Ilia's tasks: "s;
- PrintTasksInfo(updated_tasks);
- cout << "Untouched Ilia's tasks: "s;
- PrintTasksInfo(untouched_tasks);
- PrintTasksInfo(tasks.GetPersonTasksInfo("Ilia"s));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement