Advertisement
kirill1920

dairy

Jul 13th, 2020
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 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 (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. vector<string> tmp(month[mi] - 1);
  44. for (string& s : data[month[mi - 1] - 1 - i]) {
  45. data[month[mi] - 1].push_back(s);
  46. }
  47. }
  48. }
  49.  
  50. }
  51. int main() {
  52. /*****************
  53. Declaration using variables on upper function
  54. *********************************/
  55. vector<vector<string>> data(31);
  56. int mi = 0;
  57. const vector<int> month = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  58. /*****************************
  59. Declarate template variables for select work code
  60. *********************/
  61. int n;
  62. string sel;
  63. cin >> n;
  64. /*************************************************/
  65. for (int i = 0; i < n; ++i) {
  66. cin >> sel;
  67. if (sel == "ADD") {
  68. add(data);
  69. }
  70. else if (sel == "DUMP") {
  71. dump(data);
  72. }
  73. else if (sel == "NEXT") {
  74. next(data, month, mi);
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement