**
牛客 小C的记事本
链接
https://ac.nowcoder.com/acm/problem/15975(转自牛客)
总结没有写出来的原因
对栈这种数据结构还是不太清楚,没有理解到位。
用到的知识点
栈
AC代码
#include<algorithm>
#include<stack>
using namespace std;
int k;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int p;
while(cin>>p)
{
string st;
stack<string>s;
s.push(st);
while(p--)
{
int x;
cin>>x;
if(x==1)
{
cin>>st;
s.push(s.top()+st);
}
else if(x==2)
{
cin>>k;
st=s.top();
st.erase(st.size()-k);
s.push(st);
}
else if(x==3)
{
cin>>k;
st=s.top();
cout<<st[k-1]<<endl;
}
else if(x==4)
{
s.pop();
}
}
}
return 0;
}
以后做题一定要多思考问题,想想用什么存比较好,不能只局限于数组。