HDU 1022 Train Problem I
2015-01-26 14:27
351 查看
这题我的想法使用栈的思想去解决的,就是根据进站的序列加入栈中,若和出站最开始的序号相同,则出栈;然后继续进行此操作,和下一个出站的火车序号相比较。这样操作完后看看栈是否为空,就可以判断了。
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<stack> #include<queue> using namespace std; int main() { char s1[10],s2[10],s3[20][5]; int n; while(scanf("%d%s%s",&n,s1,s2)!=EOF) { stack<char> s; int top2=0,top3=0; for(int i=0;i<n;i++) { s.push(s1[i]); strcpy(s3[top3++],"in");//此处就是我的思想 while(!s.empty()) { char a=s.top(); if(a==s2[top2]) { strcpy(s3[top3++],"out"); s.pop(); top2++; } else break; } } if(s.empty()) { printf("Yes.\n"); for(int i=0;i<top3;i++) printf("%s\n",s3[i]); } else printf("No.\n"); printf("FINISH\n"); } return 0; }
相关文章推荐
- HDU 1022 Train Problem I(用栈模拟火车出入,看能否由初始顺序到达目标顺序)
- hdu 1022 Train Problem I 栈模拟
- hdu-1022 Train Problem I
- HDU 1022 Train Problem I
- hdu 1022 Train Problem I
- HDU 1022 Train Problem I (STL 栈模拟)
- hdu1022 Train Problem I
- HDOJ/HDU 1022 Train Problem I(模拟栈)
- HDU 1022 Train Problem I
- hdu 1022 Train Problem I 【栈入门经典】
- HDU 1022 Train Problem I (数据结构 —— 栈)
- hdu——1022——Train Problem I
- HDU--1022 -- Train Problem I [线性表之栈]
- HDU 【1022】Train Problem I
- HDU1022 Train Problem I【堆栈+STL+水题】
- HDU-1022 Train Problem I (栈的简单应用)
- HDU 1022 Train Problem I
- HDOJ/HDU 1022 Train Problem I(模拟栈)
- HDOJ HDU 1022 Train Problem I
- hdu 1022 Train Problem I