kirill1920

dairy

Jul 27th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<vector>
  4. using namespace std;
  5.  
  6. void dump(const vector<vector<string>>& data) {
  7.     int day;
  8.     cin >> day;
  9.     if (data[day - 1].size() == 0) {
  10.         cout << data[day - 1].size() << '\n';
  11.     }
  12.     else {
  13.         cout << data[day - 1].size() << ' ';
  14.         for (const auto& s : data[day - 1]) {
  15.             cout << s << ' ';
  16.         }
  17.         cout << endl;
  18.     }
  19. }
  20. /*
  21. We added new string for section vector with index [day-1]
  22. */
  23. void add(vector<vector<string>>& data) {
  24.     int day;
  25.     string work;
  26.     cin >> day >> work;
  27.     data[day - 1].push_back(work);
  28. }
  29. void next(vector<vector<string>>& data, const vector<int>& month, int& mi) {
  30.     if (mi == 11) {//If year is ended, we define new month
  31.         mi = 0;
  32.     }
  33.     else if (mi != 11){
  34.  
  35.         if (month[mi+1] > month[mi]) {//if new month has a bigger index, we only using resize
  36.             data.resize(month[mi+1]);
  37.             ++mi;
  38.         }
  39.  
  40.         else if (month[mi+1] < month[mi]) {
  41.             vector<string> temp;
  42.             int diff = month[mi] - month[mi+1];//search, a lot of many indexating vectors are diffirence
  43.             for (int i = diff; i > 0; --i) {
  44.                 //In this code we write a data on vector temp
  45.                 for (string& s : data[month[mi] - i]) {
  46.                     data[month[mi+1]-1].push_back(s);
  47.                 }
  48.             }
  49.             data.resize(month[mi+1]);
  50.             ++mi;
  51.         }
  52.         else if (month[mi + 1] == month[mi]) {
  53.             ++mi;
  54.         }
  55.     }
  56. }
  57. int main() {
  58.     /*****************
  59.     Declaration using variables on upper function
  60.     *********************************/
  61.     vector<vector<string>> data(31);
  62.     int mi = 0;
  63.     const vector<int> month = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  64.     /*****************************
  65.     Declarate template variables for select work code
  66.     *********************/
  67.     int n;
  68.     string sel;
  69.     cin >> n;
  70.     /*************************************************/
  71.     for (int i = 0; i < n; ++i) {
  72.         cin >> sel;
  73.         if (sel == "ADD") {
  74.             add(data);
  75.         }
  76.         else if (sel == "DUMP") {
  77.             dump(data);
  78.         }
  79.         else if (sel == "NEXT") {
  80.             next(data, month, mi);
  81.         }
  82.     }
  83. }
Add Comment
Please, Sign In to add comment