1 #include <iostream> 2 #include <stack> 3 #include <cstring> 4 5 using namespace std; 6 7 char target[10000]; 8 char source[10000]; 9 int arr[10000]; 10 11 int main() 12 { 13 stack<char>s; 14 int n; 15 while(cin>>n) 16 { 17 while(!s.empty()) 18 s.pop(); 19 memset(arr,0,sizeof(arr)); 20 cin>>source; 21 cin>>target; 22 int t1=0; 23 int t2=0; 24 int flag=1; 25 int tt=1; 26 while(t1<n) 27 { 28 if(source[t2]==target[t1]) 29 { 30 arr[tt]=1; 31 tt++; 32 arr[tt]=2; 33 tt++; 34 t1++; 35 t2++; 36 } 37 else if(!s.empty()&&s.top()==target[t1]) 38 { 39 arr[tt]=2; 40 tt++; 41 s.pop(); 42 t1++; 43 } 44 else if(t2<n) 45 { 46 s.push(source[t2]); 47 arr[tt]=1; 48 tt++; 49 t2++; 50 } 51 else 52 { 53 flag=0; 54 break; 55 } 56 } 57 if(tt==2*n+1) 58 { 59 cout<<"Yes.\n"; 60 for(int i=1;i<tt;i++) 61 { 62 if(arr[i]==1) 63 cout<<"in\n"; 64 if(arr[i]==2) 65 cout<<"out\n"; 66 } 67 cout<<"FINISH\n"; 68 } 69 else 70 { 71 cout<<"No.\n"; 72 cout<<"FINISH\n"; 73 } 74 } 75 return 0; 76 }
时间: 2024-10-08 21:10:06