SHARE
TWEET

Coursera

onezee May 31st, 2020 1,120 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. vector<vector<string>> months, tasks;
  8. vector<int> days = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  9. int checkMonths = 0;
  10.  
  11. void add(string name, int day) {
  12.     months[day-1].push_back(name);
  13. }
  14.  
  15. void dump(int day) {
  16.     tasks.resize(tasks.size() + 1);
  17.     if (months[day - 1].size() != 0) {
  18.         for (int i = 0; i < months[day - 1].size(); i++) {
  19.             tasks.back().push_back(months[day - 1][i]);
  20.         }
  21.     }
  22. }
  23.  
  24. void next() {
  25.     checkMonths++;
  26.     if (checkMonths > 11) checkMonths = 0;
  27.  
  28.     vector<vector<string>> nextMonth;
  29.     nextMonth.resize(days[checkMonths]);
  30.    
  31.     for (int i = 0; i < months.size(); i++) {
  32.         if (months[i].size() != 0) {
  33.             if (i > nextMonth.size()) {
  34.                 for (auto x : months[i]) nextMonth[nextMonth.size()-1].push_back(x);
  35.             }
  36.             else {
  37.                 for (auto x : months[i]) nextMonth[i].push_back(x);
  38.             }
  39.         }
  40.     }
  41.  
  42.     months = nextMonth;
  43. }
  44.  
  45. int main()
  46. {
  47.     int q;
  48.     cin >> q;
  49.  
  50.     months.resize(days[checkMonths]);
  51.  
  52.     int day;
  53.     string name, command;
  54.     vector<int> dumps;
  55.  
  56.     for (int i = 0; i < q; i++) {
  57.        
  58.         cin >> command;
  59.  
  60.         if (command == "ADD") {
  61.             cin >> day >> name;
  62.  
  63.             add(name, day);
  64.  
  65.         }
  66.         else if (command == "DUMP") {
  67.             cin >> day;
  68.  
  69.             dump(day);
  70.  
  71.         }
  72.         else if (command == "NEXT") {
  73.             next();
  74.         }
  75.     }
  76.  
  77.     for (int i = 0; i < tasks.size(); i++) {
  78.         cout << tasks[i].size();
  79.         if (tasks[i].size() != 0) {
  80.             for (int j = 0; j < tasks[i].size(); j++) {
  81.                 cout << " " << tasks[i][j];
  82.             }
  83.         }
  84.         cout << endl;
  85.     }
  86.  
  87.     system("PAUSE");
  88. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top