# STL Stack Exercise ```cpp= #include <iostream> #include <vector> #include <deque> #include <string> using namespace std; class solver { public: vector<deque<char> *> tubes; private: }; int main () { solver s; string input; while(cin >> input) { // cout << "Test: " << input << endl; //---parse if it is a command or expression if(input == "Insert") { deque<char> *tube = new deque<char>(); string expression; cin >> expression; for(int i = 0; i < expression.length(); i++) { tube->push_back(expression[i]); // cout << "injected: " << tube->back() << endl; } s.tubes.push_back(tube); } if(input == "Shift") { int row; cin >> row; char newSymbol; cin >> newSymbol; s.tubes[row]->push_back(newSymbol); s.tubes[row]->pop_front(); } if(input == "Reverse") { int row; cin >> row; deque<char> *temp = new deque<char>(); while(s.tubes[row]->size() > 0) { temp->push_back(s.tubes[row]->back()); s.tubes[row]->pop_back(); } while(temp->size() > 0) { s.tubes[row]->push_back(temp->front()); temp->pop_front(); } } if(input == "Transpose") { int len = s.tubes[0]->size(); while(len--) { for(int i = 0; i < s.tubes.size(); i++) { cout << s.tubes[i]->front() << " "; s.tubes[i]->push_back(s.tubes[i]->front()); s.tubes[i]->pop_front(); } cout << endl; } } if(input == "Print") { for(auto i: s.tubes) { for(auto j: *i) { cout << j << " "; } cout << endl; } } if(input == "q") { break; } } return 0; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up