ACM乐园
Love Me,Love My Code!
posts - 53,  comments - 24,  trackbacks - 0
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;
}

posted on 2011-04-05 10:07 大大木马 阅读(569) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2011年5月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(1)

随笔档案(53)

文章档案(2)

搜索

  •  

积分与排名

  • 积分 - 62912
  • 排名 - 351

最新评论

阅读排行榜

评论排行榜