HDU 1022

HDU 1022
http://acm.hdu.edu.cn/showproblem.php?pid=1022

简单模拟题,直接用stack容器做。

代码如下:

#include  < iostream >
#include 
< algorithm >
#include 
< string >
#include 
< stack >

using   namespace  std;

stack
< char >  s;
string  stra,strb;
int  i,j,k,result[ 9 ],n;
// 3 123 321
// 3 123 312
int  main()
{
    
while(cin>>n>>stra>>strb)
    
{
        i
=j=k=0;
        s.push (stra[i]);
        result[k
++]=1;
        
while(i<&& j<n)
        
{
            
if(s.size () && s.top()==strb[j])
            
{
                s.pop();
                result[k
++]=0;
                j
++;
            }

            
else
            
{
                i
++;
                
if(i==n)
                    
break;
                s.push(stra[i]);
                result[k
++]=1;
            }

        }

        
while(!s.empty ())
            s.pop();
        
if(i==n)
            cout
<<"No.\n";
        
else
        
{
            cout
<<"Yes.\n";
            
for(i=0;i<k;i++)
                
if(result[i])
                    cout
<<"in\n";
                
else
                    cout
<<"out\n";
        }

        cout
<<"FINISH\n";
    }


    
return 0;
}

你可能感兴趣的:(HDU 1022)