HDUOJ-------(1022)Train Problem I
2013-10-13 20:59
459 查看
Train Problem I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16859 Accepted Submission(s): 6300[align=left]Problem Description[/align]
As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a problem, there is only one railway where all the trains stop. So all the trains come in from one side and get out from the other side. For this problem, if train A gets into the railway first, and then train B gets into the railway before train A leaves, train A can't leave until train B leaves. The pictures below figure out the problem. Now the problem for you is, there are at most 9 trains in the station, all the trains has an ID(numbered from 1 to n), the trains get into the railway in an order O1, your task is to determine whether the trains can get out in an order O2.
#include<iostream> #include<cstdio> #include<stack> using namespace std; int main() { int n,i; while(cin>>n) { stack<char> s; bool c[24]; int rank=0,step=0; char a[12],b[12]; scanf("%s %s",b,a); for(i=0;i<n;i++) { if(a[rank]==b[i]) { /*false---》进栈,true---》出栈*/ c[step++]=false; c[step++]=true; rank++; } else { while(!s.empty()) { if(a[rank]==s.top()) { rank++; s.pop(); c[step++]=true; } else break; } s.push(b[i]); c[step++]=false; } } while(rank<n&&a[rank]==s.top()) { rank++; s.pop(); c[step++]=true; } if(!s.empty()) { printf("No.\n"); } else { puts("Yes."); for(i=0;i<2*n;i++) { if(c[i]) puts("out"); else puts("in"); } } puts("FINISH"); } return 0; }
View Code
相关文章推荐
- HDUOJ 1022 Train Problem I (栈的应用)
- HDUOJ - 1022 Train Problem I
- hdu 1022 Train Problem I(栈的应用+STL)
- HDU 1022 TRAIN PROBLEM I
- hdu 1022 Train Problem I 【栈入门经典】
- 杭电ACM OJ 1022 Train Problem I 回溯法求出栈遍历序列 很强大
- hdu1022 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(外:poj 1383 Rails)
- HDU 1022 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 <stack>
- HDU 1022 Train Problem I(用栈模拟火车出入,看能否由初始顺序到达目标顺序)
- HDU1022 Train Problem I