hdu1022 Train Problem I

 
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <stack>
 4 #include <queue>
 5 
 6 
 7 using namespace std;
 8 
 9 int main()
10 {
11     int n, a, b;
12     char str1[20], str2[20];
13     stack<char> sta;
14     queue<int> que;
15     while(scanf("%d",&n)!=-1)
16     {
17         a=0, b=0;
18         while(!sta.empty())
19             sta.pop();
20         while(!que.empty())
21             que.pop();
22 
23         scanf("%s%s",str1,str2);
24         //printf("$%s$   $%s$\n",str1,str2);
25         while(b < n)
26         {
27             if(str1[a] == str2[b])
28             {
29                 a++; b++;
30                 que.push(1);
31                 que.push(0);
32             }
33             else if(!sta.empty() && sta.top()==str2[b])
34             {
35                 b++;
36                 sta.pop();
37                 que.push(0);
38             }
39             else
40             {
41                 sta.push(str1[a++]);
42                 que.push(1);
43             }
44         }
45         //printf("a==%d   b==%d",a,b);
46         if(b==n && a == b)
47         {
48             printf("Yes.\n");
49             while(!que.empty())
50             {
51                 if(que.front()==1)
52                     printf("in\n");
53                 else
54                     printf("out\n");
55                 que.pop();
56             }
57         }
58         else
59             printf("No.\n");
60         printf("FINISH\n");
61 
62     }
63     return 0;
64 }

猜你喜欢

转载自www.cnblogs.com/Dawn-bin/p/9491423.html
今日推荐