杭电hdu 1022 Train Problem I 栈
2012-04-18 09:14
417 查看
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; }
相关文章推荐
- HDU-1022-Train Problem I
- [ACM] hdu 1022 Train Problem I(栈的使用)
- hdu1022 Train Problem I 数据结构--栈
- hdu 1022 Train Problem I
- HDU 1022 Train Problem I
- HDU 1022 Train Problem I (stack)
- HDU - 1022 - Train Problem I(栈)
- HDOJ HDU 1022 Train Problem I
- [ACM] hdu 1022 Train Problem I(栈的使用)
- HDU 1022 Train Problem I
- HDU 1022 Train Problem I
- HDU 1022 Train Problem I && PAT 5-2 列车厢调度 栈
- HDU 1022 ( Train Problem I )
- HDU-1022-Train Problem I
- 杭电1022——Train Problem I(栈的应用)
- Train Problem I hdu 1022 栈的运用
- HDU 1022 - Train Problem I
- 杭电ACM OJ 1022 Train Problem I 回溯法求出栈遍历序列 很强大
- HDU 1022 Train Problem I
- HDU_1022_Train Problem I