hdu 1022 Train Problem I<stl>

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022

View Code
 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstdlib>
 4 #include <stack>
 5 #include <cstring>
 6 using namespace std;
 7 stack<char>st;
 8 bool a[3000];
 9 char s1[1000], s2[1000];
10 int main( )
11 {
12     int N;
13     while( scanf( "%d", &N)==1 ){
14         while( !st.empty( ) ){
15             st.pop( );
16         }
17         memset( a, 0, sizeof a );
18         scanf( "%s", s1 );
19         scanf( "%s", s2 );
20         int k=0, j=0;
21         for( int i=0; i<N; ++ i ){
22             st.push(s1[i]);
23             a[k++]=0;
24             while( !st.empty( )&&st.top()==s2[j]){
25                 j++;
26                 a[k++]=1;
27                 st.pop( );
28             }
29         }
30         if( !st.empty( )){
31             puts( "No." );
32             puts("FINISH");
33         }else{
34             puts( "Yes." );
35             for( int i=0;i<k; ++ i ){
36                 if( a[i] )puts( "out" );
37                 else puts( "in" );
38             }
39             puts("FINISH");
40         }
41     }
42     return 0;
43 }
原文地址:https://www.cnblogs.com/jian1573/p/3050234.html