http://acm.hdu.edu.cn/showproblem.php?pid=1022
栈的模板题。
1 #include<iostream> 2 #include<cstdio> 3 #include<stack> 4 #include<string> 5 #include<cstring> 6 using namespace std; 7 string a,b; 8 int c[100]; 9 int main() 10 { 11 // freopen("1.txt","r",stdin); 12 int n; 13 stack<char>jk; 14 while(scanf("%d",&n)!=EOF) 15 { 16 stack<int>jk; 17 while(!jk.empty()) 18 jk.pop(); 19 cin>>a>>b; 20 int k=0,j=0; 21 for(int i=0; i<n; i++) 22 { 23 jk.push(a[i]); 24 c[k++]=1; 25 while(j<n && !jk.empty()) 26 { 27 if(jk.top()==b[j]) 28 { 29 j++; 30 jk.pop(); 31 c[k++]=0; 32 } 33 else 34 break; 35 } 36 } 37 38 if(jk.empty()) 39 { 40 cout<<"Yes."<<endl; 41 for(int i=0; i<k; i++) 42 { 43 if(c[i]==1) 44 cout<<"in"<<endl; 45 else 46 cout<<"out"<<endl; 47 } 48 cout<<"FINISH"<<endl; 49 } 50 else 51 cout<<"No."<<endl<<"FINISH"<<endl; 52 } 53 return 0; 54 }