Train Problem I

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

View Code
 1 #include<iostream>
 2 #include<stack>
 3 #include<cstring>
 4 using namespace std ;
 5 int main()
 6 {
 7     int n, i, j, k, d[18] ;
 8     string a, b ;
 9     while(cin>>n>>a>>b)
10     {
11         i = j = k = 0 ;
12         stack<int>s ;
13         int flag = 1 ;
14         while(j<n)
15         {
16             if(a[i]==b[j])
17             {
18                 i++ ;
19                 j++ ;
20                 d[k++] = 1 ;
21                 d[k++] = 0 ;
22             }
23             else if(!s.empty()&&s.top()==b[j])
24             {
25                 d[k++] = 0 ;
26                 s.pop() ;
27                 j++ ;
28             }
29             else if(i<n)
30             {
31                 d[k++] = 1 ;
32                 s.push(a[i]) ;
33                 i++ ;
34             }
35             else
36             {
37                 flag = 0 ;
38                 break ;
39             }
40         }
41         if(flag)
42         {
43             cout<<"Yes."<<endl ;
44             for(i=0; i<k; i++)
45             if(d[i])
46             cout<<"in"<<endl ;
47             else
48             cout<<"out"<<endl ;
49         }
50         else
51         cout<<"No."<<endl ;
52         cout<<"FINISH"<<endl ;
53     }
54     return 0 ;
55 }

用G++提交

posted @ 2013-03-24 23:26  yelan@yelan  阅读(130)  评论(0编辑  收藏  举报