Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<vector>
- using namespace std;
- void dump(const vector<vector<string>>& data) {
- int day;
- cin >> day;
- if (data[day - 1].size() == 0) {
- cout << data[day - 1].size() << '\n';
- }
- else {
- cout << data[day - 1].size() << ' ';
- for (const auto& s : data[day - 1]) {
- cout << s << ' ';
- }
- cout << endl;
- }
- }
- /*
- We added new string for section vector with index [day-1]
- */
- void add(vector<vector<string>>& data) {
- int day;
- string work;
- cin >> day >> work;
- data[day - 1].push_back(work);
- }
- void next(vector<vector<string>>& data, const vector<int>& month, int& mi) {
- if (mi == 11) {//If year is ended, we define new month
- mi = 0;
- }
- else if (mi != 11){
- if (month[mi+1] > month[mi]) {//if new month has a bigger index, we only using resize
- data.resize(month[mi+1]);
- ++mi;
- }
- else if (month[mi+1] < month[mi]) {
- vector<string> temp;
- int diff = month[mi] - month[mi+1];//search, a lot of many indexating vectors are diffirence
- for (int i = diff; i > 0; --i) {
- //In this code we write a data on vector temp
- for (string& s : data[month[mi] - i]) {
- data[month[mi+1]-1].push_back(s);
- }
- }
- data.resize(month[mi+1]);
- ++mi;
- }
- else if (month[mi + 1] == month[mi]) {
- ++mi;
- }
- }
- }
- int main() {
- /*****************
- Declaration using variables on upper function
- *********************************/
- vector<vector<string>> data(31);
- int mi = 0;
- const vector<int> month = { 31,28,31,30,31,30,31,31,30,31,30,31 };
- /*****************************
- Declarate template variables for select work code
- *********************/
- int n;
- string sel;
- cin >> n;
- /*************************************************/
- for (int i = 0; i < n; ++i) {
- cin >> sel;
- if (sel == "ADD") {
- add(data);
- }
- else if (sel == "DUMP") {
- dump(data);
- }
- else if (sel == "NEXT") {
- next(data, month, mi);
- }
- }
- }
Add Comment
Please, Sign In to add comment