Advertisement
AyratT

Untitled

Oct 26th, 2022 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. #include <tuple>
  5.  
  6. using namespace std;
  7.  
  8. // Перечислимый тип для статуса задачи
  9. enum class TaskStatus {
  10.     NEW,          // новая
  11.     IN_PROGRESS,  // в разработке
  12.     TESTING,      // на тестировании
  13.     DONE          // завершена
  14. };
  15.  
  16. // Объявляем тип-синоним для map<TaskStatus, int>,
  17. // позволяющего хранить количество задач каждого статуса
  18. using TasksInfo = map<TaskStatus, int>;
  19.  
  20. class TeamTasks {
  21. public:
  22.     // Получить статистику по статусам задач конкретного разработчика
  23.     const TasksInfo& GetPersonTasksInfo(const string& person) const {
  24.         return name_to_tasks_.at(person);
  25.     };
  26.  
  27.     // Добавить новую задачу (в статусе NEW) для конкретного разработчитка
  28.     void AddNewTask(const string& person) {
  29.         ++name_to_tasks_[person][TaskStatus::NEW];
  30.         //name_to_tasks_[person][TaskStatus::IN_PROGRESS] = 0;
  31.         //name_to_tasks_[person][TaskStatus::TESTING] = 0;
  32.         //name_to_tasks_[person][TaskStatus::DONE] = 0;
  33.     };
  34.     /*void AddIN_PROGRESSTask(const string& person) {
  35.         ++name_to_tasks_[person][TaskStatus::IN_PROGRESS];
  36.     };
  37.     void AddTESTINGTask(const string& person) {
  38.         ++name_to_tasks_[person][TaskStatus::TESTING];
  39.     };
  40.     void AddDONEask(const string& person) {
  41.         ++name_to_tasks_[person][TaskStatus::DONE];
  42.     };*/
  43.     // Обновить статусы по данному количеству задач конкретного разработчика,
  44.     // подробности см. ниже
  45.     tuple<TasksInfo, TasksInfo> PerformPersonTasks(const string& person, int task_count) {
  46.        
  47.         TasksInfo untouched_tasks;
  48.         TasksInfo updated_tasks;
  49.         if (name_to_tasks_.count(person) > 0) {
  50.             TasksInfo tasks_to_amount = name_to_tasks_.at(person);
  51.             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]);
  52.             //cout << sum << endl;
  53.             if (sum < task_count) {
  54.                 task_count = sum;
  55.             }
  56.             for (auto [Task_Status, Task_amount] : name_to_tasks_.at(person)) {
  57.                 TaskStatus next_Task_Status = static_cast<TaskStatus>(static_cast<int>(Task_Status) + 1);
  58.                 if (Task_amount <= task_count) {
  59.                     tasks_to_amount[Task_Status] -= min(task_count, Task_amount);
  60.                     tasks_to_amount[next_Task_Status] += Task_amount;
  61.                     updated_tasks[next_Task_Status] = Task_amount;
  62.                     task_count -= Task_amount;
  63.                 }
  64.                 else {
  65.                     tasks_to_amount[Task_Status] -= task_count;
  66.                     tasks_to_amount[next_Task_Status] += task_count;
  67.                     updated_tasks[next_Task_Status] = task_count;
  68.                     untouched_tasks[Task_Status] = name_to_tasks_.at(person).at(Task_Status) - task_count;
  69.                     task_count = 0;
  70.                     //break;
  71.                 }
  72.                 if (Task_Status == TaskStatus::TESTING) {
  73.                     break;
  74.                 }
  75.             }
  76.             for (auto [Task_Status, Task_amount] : tasks_to_amount) {
  77.                 name_to_tasks_.at(person)[Task_Status] = Task_amount;
  78.             }
  79.         }    
  80.         return tuple(updated_tasks, untouched_tasks);
  81.     };
  82. private:
  83.     map <string, TasksInfo> name_to_tasks_;
  84. };
  85.  
  86. // Принимаем словарь по значению, чтобы иметь возможность
  87. // обращаться к отсутствующим ключам с помощью [] и получать 0,
  88. // не меняя при этом исходный словарь.
  89. /*void PrintTasksInfo(TasksInfo tasks_info) {
  90.     cout << tasks_info[TaskStatus::NEW] << "/"s
  91.         << tasks_info[TaskStatus::IN_PROGRESS] << "/"s
  92.         << tasks_info[TaskStatus::TESTING] << "/"s
  93.         << tasks_info[TaskStatus::DONE] << ""s << endl;
  94. }
  95.  
  96. int main() {
  97.     TeamTasks tasks;
  98.     tasks.AddNewTask("Ilia");
  99.     for (int i = 0; i < 3; ++i) {
  100.         tasks.AddNewTask("Ivan");
  101.     }
  102.     cout << "Ilia's tasks: ";
  103.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ilia"));
  104.     cout << "Ivan's tasks: ";
  105.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"));
  106.  
  107.     TasksInfo updated_tasks, untouched_tasks;
  108.  
  109.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan", 2);
  110.     cout << "Updated Ivan's tasks: ";
  111.     PrintTasksInfo(updated_tasks);
  112.     cout << "Untouched Ivan's tasks: ";
  113.     PrintTasksInfo(untouched_tasks);
  114.  
  115.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan", 2);
  116.     cout << "Updated Ivan's tasks: ";
  117.     PrintTasksInfo(updated_tasks);
  118.     cout << "Untouched Ivan's tasks: ";
  119.     PrintTasksInfo(untouched_tasks);
  120.  
  121.  
  122.  
  123.  
  124.  
  125.     for (int i = 0; i < 5; ++i) {
  126.         tasks.AddNewTask("Ivan"s);
  127.     }
  128.     for (int i = 0; i < 0; ++i) {
  129.         tasks.AddIN_PROGRESSTask("Ivan"s);
  130.     }
  131.     for (int i = 0; i < 0; ++i) {
  132.         tasks.AddTESTINGTask("Ivan"s);
  133.     }
  134.     for (int i = 0; i < 0; ++i) {
  135.         tasks.AddDONEask("Ivan"s);
  136.     }
  137.  
  138.     cout << "Ivan's tasks before: "s;
  139.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  140.  
  141.     //TasksInfo updated_tasks, untouched_tasks;
  142.  
  143.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 6);
  144.     cout << "PerformPersonTasks(6)" << endl;
  145.     cout << "Updated Ivan's tasks: "s;
  146.     PrintTasksInfo(updated_tasks);
  147.     cout << "Untouched Ivan's tasks: "s;
  148.     PrintTasksInfo(untouched_tasks);
  149.     cout << "Ivan's tasks after: "s;
  150.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  151.     cout << endl;
  152.     for (int i = 0; i < 1200; ++i) {
  153.         tasks.AddNewTask("Ivan"s);
  154.     }
  155.     for (int i = 0; i < 2; ++i) {
  156.         tasks.AddIN_PROGRESSTask("Ivan"s);
  157.     }
  158.     for (int i = 0; i < 2; ++i) {
  159.         tasks.AddTESTINGTask("Ivan"s);
  160.     }
  161.     for (int i = 0; i < 16; ++i) {
  162.         tasks.AddDONEask("Ivan"s);
  163.     }
  164.  
  165.     cout << "Ivan's tasks before: "s;
  166.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  167.  
  168.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 1206);
  169.     cout << "PerformPersonTasks(1206)" << endl;
  170.     cout << "Updated Ivan's tasks: "s;
  171.     PrintTasksInfo(updated_tasks);
  172.     cout << "Untouched Ivan's tasks: "s;
  173.     PrintTasksInfo(untouched_tasks);
  174.     cout << "Ivan's tasks after: "s;
  175.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  176.     cout << endl;
  177.  
  178.  
  179.     for (int i = 0; i < 1; ++i) {
  180.         tasks.AddNewTask("Ivan"s);
  181.     }
  182.     for (int i = 0; i < 2; ++i) {
  183.         tasks.AddIN_PROGRESSTask("Ivan"s);
  184.     }
  185.     for (int i = 0; i < 3; ++i) {
  186.         tasks.AddTESTINGTask("Ivan"s);
  187.     }
  188.     for (int i = 0; i < 4; ++i) {
  189.         tasks.AddDONEask("Ivan"s);
  190.     }
  191.  
  192.     cout << "Ivan's tasks before: "s;
  193.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  194.  
  195.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 1000);
  196.     cout << "PerformPersonTasks(1000)" << endl;
  197.     cout << "Updated Ivan's tasks: "s;
  198.     PrintTasksInfo(updated_tasks);
  199.     cout << "Untouched Ivan's tasks: "s;
  200.     PrintTasksInfo(untouched_tasks);
  201.     cout << "Ivan's tasks after: "s;
  202.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  203.     cout << endl;
  204.  
  205.     for (int i = 0; i < 1; ++i) {
  206.         tasks.AddNewTask("Ivan"s);
  207.     }
  208.     for (int i = 0; i < 0; ++i) {
  209.         tasks.AddIN_PROGRESSTask("Ivan"s);
  210.     }
  211.     for (int i = 0; i < 0; ++i) {
  212.         tasks.AddTESTINGTask("Ivan"s);
  213.     }
  214.     for (int i = 0; i < 0; ++i) {
  215.         tasks.AddDONEask("Ivan"s);
  216.     }
  217.  
  218.     cout << "Ivan's tasks before: "s;
  219.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  220.  
  221.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 1);
  222.     cout << "PerformPersonTasks(1)" << endl;
  223.     cout << "Updated Ivan's tasks: "s;
  224.     PrintTasksInfo(updated_tasks);
  225.     cout << "Untouched Ivan's tasks: "s;
  226.     PrintTasksInfo(untouched_tasks);
  227.     cout << "Ivan's tasks after: "s;
  228.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  229.     cout << endl;
  230.  
  231.     for (int i = 0; i < 1; ++i) {
  232.         tasks.AddNewTask("Ivan"s);
  233.     }
  234.     for (int i = 0; i < 0; ++i) {
  235.         tasks.AddIN_PROGRESSTask("Ivan"s);
  236.     }
  237.     for (int i = 0; i < 12; ++i) {
  238.         tasks.AddTESTINGTask("Ivan"s);
  239.     }
  240.     for (int i = 0; i < 3; ++i) {
  241.         tasks.AddDONEask("Ivan"s);
  242.     }
  243.  
  244.     cout << "Ivan's tasks before: "s;
  245.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  246.  
  247.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 100);
  248.     cout << "PerformPersonTasks(100)" << endl;
  249.     cout << "Updated Ivan's tasks: "s;
  250.     PrintTasksInfo(updated_tasks);
  251.     cout << "Untouched Ivan's tasks: "s;
  252.     PrintTasksInfo(untouched_tasks);
  253.     cout << "Ivan's tasks after: "s;
  254.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  255.     cout << endl;
  256.  
  257.     for (int i = 0; i < 5; ++i) {
  258.         tasks.AddNewTask("Ivan"s);
  259.     }
  260.     for (int i = 0; i < 5; ++i) {
  261.         tasks.AddIN_PROGRESSTask("Ivan"s);
  262.     }
  263.     for (int i = 0; i < 5; ++i) {
  264.         tasks.AddTESTINGTask("Ivan"s);
  265.     }
  266.     for (int i = 0; i < 0; ++i) {
  267.         tasks.AddDONEask("Ivan"s);
  268.     }
  269.  
  270.     cout << "Ivan's tasks before: "s;
  271.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  272.  
  273.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 10);
  274.     cout << "PerformPersonTasks(10)" << endl;
  275.     cout << "Updated Ivan's tasks: "s;
  276.     PrintTasksInfo(updated_tasks);
  277.     cout << "Untouched Ivan's tasks: "s;
  278.     PrintTasksInfo(untouched_tasks);
  279.     cout << "Ivan's tasks after: "s;
  280.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  281.     cout << endl;
  282.  
  283.  
  284.     for (int i = 0; i < 5; ++i) {
  285.         tasks.AddNewTask("Ivan"s);
  286.     }
  287.     for (int i = 0; i < 5; ++i) {
  288.         tasks.AddIN_PROGRESSTask("Ivan"s);
  289.     }
  290.     for (int i = 0; i < 0; ++i) {
  291.         tasks.AddTESTINGTask("Ivan"s);
  292.     }
  293.     for (int i = 0; i < 0; ++i) {
  294.         tasks.AddDONEask("Ivan"s);
  295.     }
  296.  
  297.     cout << "Ivan's tasks before: "s;
  298.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  299.  
  300.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Ivan"s, 5);
  301.     cout << "PerformPersonTasks(5)" << endl;
  302.     cout << "Updated Ivan's tasks: "s;
  303.     PrintTasksInfo(updated_tasks);
  304.     cout << "Untouched Ivan's tasks: "s;
  305.     PrintTasksInfo(untouched_tasks);
  306.     cout << "Ivan's tasks after: "s;
  307.     PrintTasksInfo(tasks.GetPersonTasksInfo("Ivan"s));
  308.     cout << endl;
  309. }*/
  310.  
  311. void PrintTasksInfo(const TasksInfo& tasks_info) {
  312.     if (tasks_info.count(TaskStatus::NEW)) {
  313.         std::cout << "NEW: " << tasks_info.at(TaskStatus::NEW) << " ";
  314.     }
  315.     if (tasks_info.count(TaskStatus::IN_PROGRESS)) {
  316.         std::cout << "IN_PROGRESS: " << tasks_info.at(TaskStatus::IN_PROGRESS) << " ";
  317.     }
  318.     if (tasks_info.count(TaskStatus::TESTING)) {
  319.         std::cout << "TESTING: " << tasks_info.at(TaskStatus::TESTING) << " ";
  320.     }
  321.     if (tasks_info.count(TaskStatus::DONE)) {
  322.         std::cout << "DONE: " << tasks_info.at(TaskStatus::DONE) << " ";
  323.     }
  324. }
  325.  
  326. void PrintTasksInfo(const TasksInfo& updated_tasks, const TasksInfo& untouched_tasks) {
  327.     std::cout << "Updated: [";
  328.     PrintTasksInfo(updated_tasks);
  329.     std::cout << "] ";
  330.  
  331.     std::cout << "Untouched: [";
  332.     PrintTasksInfo(untouched_tasks);
  333.     std::cout << "] ";
  334.  
  335.     std::cout << std::endl;
  336. }
  337.  
  338. int main() {
  339.     TeamTasks tasks;
  340.     TasksInfo updated_tasks;
  341.     TasksInfo untouched_tasks;
  342.  
  343.  
  344.     // TEST 3
  345.     std::cout << "\nLisa" << std::endl;
  346.  
  347.     for (auto i = 0; i < 5; ++i) {
  348.         tasks.AddNewTask("Lisa");
  349.     }
  350.  
  351.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 5);
  352.     PrintTasksInfo(updated_tasks, untouched_tasks);  // [{"IN_PROGRESS": 5}, {}]
  353.  
  354.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 5);
  355.     PrintTasksInfo(updated_tasks, untouched_tasks);  // [{"TESTING": 5}, {}]
  356.  
  357.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 1);
  358.     PrintTasksInfo(updated_tasks, untouched_tasks);  // [{"DONE": 1}, {"TESTING": 4}]
  359.  
  360.     for (auto i = 0; i < 5; ++i) {
  361.         tasks.AddNewTask("Lisa");
  362.     }
  363.  
  364.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 2);
  365.     PrintTasksInfo(updated_tasks, untouched_tasks);  // [{"IN_PROGRESS": 2}, {"NEW": 3, "TESTING": 4}]
  366.  
  367.     PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa"));  // {"NEW": 3, "IN_PROGRESS": 2, "TESTING": 4, "DONE": 1}
  368.     std::cout << std::endl;
  369.  
  370.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 4);
  371.     PrintTasksInfo(updated_tasks, untouched_tasks);  // [{"IN_PROGRESS": 3, "TESTING": 1}, {"IN_PROGRESS": 1, "TESTING": 4}]
  372.  
  373.     PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa"));  // {"IN_PROGRESS": 4, "TESTING": 5, "DONE": 1}
  374.     std::cout << std::endl;
  375.  
  376.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 5);
  377.     PrintTasksInfo(updated_tasks, untouched_tasks);  // [{"TESTING": 4, "DONE": 1}, {"TESTING": 4}]
  378.  
  379.     PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa"));  // {"TESTING": 8, "DONE": 2}
  380.     std::cout << std::endl;
  381.  
  382.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 10);
  383.     PrintTasksInfo(updated_tasks, untouched_tasks);  // [{"DONE": 8}, {}]
  384.  
  385.     PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa"));  // {"DONE": 10}
  386.     std::cout << std::endl;
  387.  
  388.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 10);
  389.     PrintTasksInfo(updated_tasks, untouched_tasks);  // [{}, {}]
  390.  
  391.     PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa"));  // {"DONE": 10}
  392.     std::cout << std::endl;
  393.  
  394.     tasks.AddNewTask("Lisa");
  395.  
  396.     PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa"));  // {"NEW": 1, "DONE": 10}
  397.     std::cout << std::endl;
  398.  
  399.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Lisa", 2);
  400.     PrintTasksInfo(updated_tasks, untouched_tasks);  // [{"IN_PROGRESS": 1}, {}]
  401.  
  402.     PrintTasksInfo(tasks.GetPersonTasksInfo("Lisa"));  // {"IN_PROGRESS": 1, "DONE": 10}
  403.     std::cout << std::endl;
  404.  
  405.     tie(updated_tasks, untouched_tasks) = tasks.PerformPersonTasks("Bob", 3);
  406.     PrintTasksInfo(updated_tasks, untouched_tasks);  // [{}, {}]
  407.  
  408.     return 0;
  409. }
  410.  
  411.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement