ShermanUA

Monthly_affairs

Apr 11th, 2020
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <string>
  4. #include <map>
  5.  
  6. void next(int month, std::map<int, std::vector<std::string>>& tasks)
  7. {
  8.     int months[12]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  9.     if (months[month] < months[month-1])
  10.     {
  11.         for (int i = months[month-1]; i > months[month]; --i)
  12.         {
  13.             for(const auto& t : tasks[i])
  14.             {
  15.                 tasks[months[month]].push_back(t);
  16.             }
  17.             tasks[i].clear();
  18.         }
  19.  
  20.     }
  21. }
  22.  
  23. void add(std::map<int, std::vector<std::string>>& tasks) {
  24.     int day;
  25.     std::cin >> day;
  26.     std::string task;
  27.     std::cin >> task;
  28.     tasks[day].push_back(task);
  29. }
  30.  
  31. void dump(std::map<int, std::vector<std::string>>& tasks)
  32. {
  33.     int day;
  34.     std::cin >> day;
  35.     std::cout << tasks[day].size() << " ";
  36.     for (const auto& t : tasks[day])
  37.     {
  38.         std::cout << t << " ";
  39.     }
  40.     std::cout << std::endl;
  41. }
  42.  
  43.  
  44. int main()
  45. {
  46.     int q;
  47.     std::cin >> q;
  48.     std::map<int, std::vector<std::string>> tasks;
  49.  
  50.     int month = 0;
  51.     for (int i = 0; i < q; i++)
  52.     {
  53.         std::string action;
  54.         std::cin >> action;
  55.         if (action == "NEXT") {
  56.             month += 1;
  57.             next(month, tasks);
  58.         }
  59.         else
  60.         {
  61.             if (action == "ADD") {
  62.                 add(tasks);
  63.             }
  64.             else if(action == "DUMP")
  65.             {
  66.                 dump(tasks);
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment