Advertisement
kirill1920

dairy_final

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