Simple Text Editor

Problem Link

<Solution>

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,k,len;
cin>>n;
string s=””,s1,a=””;
stack<string>st;
for(i=0;i<n;i++)
{int q;
cin>>q;
switch(q)
{
case 1: cin>>s1;
st.push(s);
s+=s1;
break;
case 2:cin>>k;
st.push(s);
a=s;
len=a.size();
s=””;
s.append(a,0,len-k);
break;
case 3: cin>>k;
cout<<s[k-1]<<endl;
break;
case 4:
s=st.top();
st.pop();
break;
}
}
}

Advertisements

About waprogramming

I am in CSE,from CUET
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s