题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1022

None.gif#include <iostream>
None.gif#include 
<string>
None.gif#include 
<stack>
None.gif#include 
<vector>
None.gif
using namespace std;
None.gif
None.gif
string strIn,strOut;
None.gifstack
<char> strTmp;//临时栈
None.gif
vector<string> strInfo;
None.gif
None.gif
int main(int argc,char* argv[])
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
int n,i,curPos;
InBlock.gif    
char ch;
InBlock.gif    
while(cin>>n)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        cin
>>strIn>>strOut;
InBlock.gif        curPos 
= 0;//out指针
InBlock.gif
        while(!strTmp.empty())
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            strTmp.pop();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
while(strInfo.size()!=0)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            strInfo.pop_back();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
for(i=0;i<strIn.length();++i)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(strTmp.empty()==false)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{//栈不空
InBlock.gif
                ch = strTmp.top();
InBlock.gif                
while(strOut[curPos]==ch&&(strTmp.empty()==false))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{//相等,出栈
InBlock.gif
                    strTmp.pop();
InBlock.gif                    strInfo.push_back(
"out");
InBlock.gif                    curPos
++;//当前指针后移
InBlock.gif
                    if(strTmp.empty())
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
break;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    ch 
= strTmp.top();
ExpandedSubBlockEnd.gif                }

InBlock.gif                strTmp.push(strIn[i]);
InBlock.gif                strInfo.push_back(
"in");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{//栈空
InBlock.gif
                    strTmp.push(strIn[i]);//入栈
InBlock.gif
                    strInfo.push_back("in");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
while(!strTmp.empty())
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ch 
= strTmp.top();
InBlock.gif            strInfo.push_back(
"out");
InBlock.gif            
if(ch!=strOut[curPos])
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                cout
<<"No."<<endl;
InBlock.gif                
break;
ExpandedSubBlockEnd.gif            }

InBlock.gif            strTmp.pop();
InBlock.gif            curPos
++;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
if(strTmp.empty())
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            cout
<<"Yes."<<endl;
InBlock.gif            
for(i=0;i<strInfo.size();++i)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                cout
<<strInfo[i]<<endl;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        cout
<<"FINISH"<<endl;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
return 0;
ExpandedBlockEnd.gif}

None.gif