Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3548 Accepted Submission(s): 1299
3 123 321 3 123 312
Yes. in in in out out out FINISH No. FINISHFor the first Sample Input, we let train 1 get in, then train 2 and train 3. So now train 3 is at the top of the railway, so train 3 can leave first, then train 2 and train 1. In the second Sample input, we should let train 3 leave first, so we have to let train 1 get in, then train 2 and train 3. Now we can let train 3 leave. But after that we can't let train 1 leave before train 2, because train 2 is at the top of the railway at the moment. So we output "No.".HintHint思路:每次的数据完后都要清栈,不然会WA。。。我就是因为这个错误一直在WA - -||代码如下:#include <stdio.h> #include <stack> using namespace std; int main() { int n,i,j,num; char in[10],out[10]; int flag[20]; while(scanf("%d",&n)!=EOF) { stack<char> s; i=j=num=0; scanf("%s",in); scanf("%s",out); while(j<n) { if(s.empty() || s.top()!=out[j] && i<n) { s.push(in[i]); flag[num++]=1; i++; } else { if(s.top()==out[j]) { s.pop(); flag[num++]=0; j++; } else break; } } if(s.empty()) { printf("Yes./n"); for(i=0;i<num;i++) { if(flag[i]==1) printf("in/n"); else printf("out/n"); } printf("FINISH/n"); } else printf("No./nFINISH/n"); } return 0; }