You are viewing a single comment's thread. Return to all comments →
stack<string> state; int q , t, del, pr; int i = 0; string s, res; cin>>q; while(i < q) { cin>>t; if(t ==1) { //Append cin>>s; state.push(res); res +=s; }else if(t ==2) { //Delete cin >> del; int index = res.length() - del; if(index < res.length()) { state.push(res); res = res.erase(index,res.length()); } }else if(t ==3) { //Print cin>>pr; int index = pr -1; if(index < res.length()) { cout<<res[index] << endl; } }else if(t ==4) { //Undo if(!state.empty()) { string tp = state.top(); res = tp; state.pop(); } } i++; } return 0;
Seems like cookies are disabled on this browser, please enable them to open this website
Simple Text Editor
You are viewing a single comment's thread. Return to all comments →