一道简单的栈模拟题,但是出错了,出错原因是考虑入栈一次后应当考虑多次出栈的情况,我只考虑了一次。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022
也算一个教训,以后再做和栈模拟相关的题目可(zheng)能(qu)不出错了!
#include
using namespace std;
const int maxn = 1e3 + 10;
queueque;
char in[maxn],out[maxn];
stackst;
int n;
int main()
{
while(~scanf("%d",&n))
{
while(!st.empty())
st.pop();
while(!que.empty())
que.pop();
scanf("%s %s",&in,&out);
int top = 0,a,b;
for(int i = 0; i < n; ++i)
{
st.push(in[i]);
que.push("in");
while(!st.empty()&&st.top() == out[top])
{
que.push("out");
st.pop();
top++;
}
}
if(st.empty())
{
printf("Yes.\n");
while(!que.empty())
{
cout << que.front() <