栈+队列
1 #include<stdio.h> 2 #include<string.h> 3 #include<stack> 4 #include<queue> 5 using namespace std; 6 int main() 7 { 8 int n; 9 char a[11],b[11]; 10 stack<char>s; 11 queue<int>q; 12 while(scanf("%d",&n)!=EOF) 13 { 14 memset(a,0,sizeof(a)); 15 memset(b,0,sizeof(b)); 16 scanf("%s",&a); 17 scanf("%s",&b); 18 int i=0,j=0; 19 while(!s.empty()) s.pop(); 20 while(!q.empty()) q.pop(); 21 while(i<n) 22 { 23 s.push(a[i]); 24 q.push(1); 25 while(!s.empty()&&s.top()==b[j]) 26 { 27 s.pop(); 28 q.push(0); 29 j++; 30 } 31 i++; 32 } 33 if(s.empty()) 34 { 35 printf("Yes. "); 36 while(!q.empty()) 37 { 38 if(q.front()) printf("in "); 39 else printf("out "); 40 q.pop(); 41 } 42 } 43 else printf("No. "); 44 printf("FINISH "); 45 } 46 }