HDU 1022 Train Problem I

火车进出站

做了好长时间,用数组类型存储的,没做出来,之后用栈操作,很快就搞定了。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <stack>
 5 
 6 using namespace std;
 7 
 8 int main(){
 9     int n;int a[50];
10     stack <char> s;
11     char s1[20],s2[20];
12     while(~scanf("%d %s%s",&n,s1,s2)){
13         while(!s.empty()) s.pop();
14         memset(a,-1,sizeof(a));
15         int j=0,k=0;
16         for(int i=0;i<n;i++){
17             s.push(s1[i]);
18             a[j++]=1;
19             while(!s.empty() && s2[k]==s.top()){
20                 a[j++]=0;
21                 s.pop();
22                 k++;
23             }
24         }
25         if(k==n){
26             printf("Yes.
");
27             for(int i=0;i<j;i++){
28                 if(a[i]==0)
29                     printf("out
");
30                 else
31                     printf("in
");
32 
33             }
34         }
35         else
36             printf("No.
");
37         printf("FINISH
");
38     }
39 
40 
41     return 0;
42 }
---------------- 人们生成的最美好的岁月其实就是最痛苦的时候,只是事后回忆起来的时候才那么幸福。
原文地址:https://www.cnblogs.com/livelihao/p/5162968.html