你在写作文。你有三种操作。
一行一个整数 n 表示操作数量。
之后 n 行依次给出 n 个命令,保证命令合法。
每行输出一个字母表示一次询问的答案。\
输入
7
T a
T b
T c
Q 2
U 2
T c
Q 2
输出
b
c
数据范围
n<=200\
注:代码十分鬼畜,不喜勿喷,谢谢。
#include<bits/stdc++.h>
using namespace std;
int n,tail=0;
char cmd1,cmd2;
string s;
struct cmd
{
char cmd1,cmd2;
}a[10010];
stack<cmd>cmds;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].cmd1>>a[i].cmd2;
cmds.push(a[i]);
if(cmd1=='T')
{
s[tail+1]=cmd2;
tail++;
}
else if(cmd1=='U')
{
for(int j=1;j<=a[i].cmd2;j++)
{
if(cmds.top().cmd1=='U')
{
tail+=cmds.top().cmd2;
cmds.pop();
}
else if(cmds.top().cmd1=='T')
{
tail--;
cmds.pop();
}
}
}
else if(cmd1=='Q')
{
cout<<s[cmd2-'0']<<endl;
}
}
return 0;
}