We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
myc++sol:#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>#include<stack>usingnamespacestd;intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */strings="";stack<string>st;intn;cin>>n;for(inti=0;i<n;i++){intk=0;cin>>k;if(k==1){stringstr;cin>>str;st.push(s);s.append(str);}if(k==2)//last k character{intno;cin>>no;st.push(s);while(no>0){s.pop_back();no--;}}if(k==3)//print kth char{inth;cin>>h;cout<<s[h-1]<<endl;}elseif(k==4){if(!st.empty()){s=st.top();st.pop();}}}return0;}
Cookie support is required to access HackerRank
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 →