http://acm.hdu.edu.cn/showproblem.php?pid=1022
栈的简单实现。
#include <iostream>
using namespace std;
#include <string>
#include <queue>
#include <stack>
queue<string >Q;
stack<char >S;
int main()
{
int n;
char train1[10], train2[10], tmp;
int i, j;
while(scanf("%d", &n)!=EOF){
scanf("%s%s", train1, train2);
// puts(train1);
// puts(train2);
S.push(train1[0]);
Q.push("in");
for(i = 1, j = 0; j < n;){
if(S.empty()&&i < n){
S.push(train1[i]);
Q.push("in");
i ++;
}
tmp = S.top();
// printf("%c\n", tmp);
if(tmp == train2[j]){
S.pop();
Q.push("out");
j ++;
}
else{
if(i < n){
S.push(train1[i]);
Q.push("in");
i ++;
}
else break;
}
}
if(i >= n && j >= n){
printf("Yes.\n");
while(!Q.empty()){
string s = Q.front();
Q.pop();
cout<<s<<endl;
}
}
else {
printf("No.\n");
}
printf("FINISH\n");
while(!Q.empty())Q.pop();
while(!S.empty())S.pop();
}
return 0;
}