zoukankan      html  css  js  c++  java
  • hoj 1067 Rails //poj1363 Rails 栈的简单应用

    //ACM ICPC Central European Regional 1997

    /*

    简单的栈的应用,可惜WA了好几次

    poj上要把最后的while后的cout<<endl;去掉

    */

    #include <iostream>

    #include <stack>

    #include <cstdio>

    using namespace std;

    const int X = 1005;

    int a[X],b[X];

    int main()

    {

       freopen("sum.in","r",stdin);

       freopen("sum.out","w",stdout);

       int n,x,t = 0;

       while(cin>>n,n)

       {

          if(t++)

             cout<<endl;

          while(cin>>x,x)

          {

             stack<int> s;

             a[1] = x;

             for(int i=2;i<=n;i++)

                scanf("%d",a+i);

             int cnt = 1;

             int B = 1;

             for(int i=1;i<=n;i++)

             {

                s.push(i);

                if(s.top()==a[cnt])

                {

                    while(!s.empty())

                    {

                       if(s.top()==a[cnt])

                       {

                          b[B++] = s.top();

                          cnt++;

                          s.pop();

                       }

                       else

                          break;

                    }

                }

             }

             bool flag = true;

             for(int i=1;i<=n;i++)

                if(a[i]!=b[i])

                {

                    flag = false;

                    cout<<"No"<<endl;

                    break;

                }

             if(flag)

                cout<<"Yes"<<endl;

          }

       }

       cout<<endl;

       return 0;

    }

     

    编辑器加载中...

  • 相关阅读:
    《必须知道的.net》读后感 转
    Web Service
    设计模式
    对做“互联网产品”的一些想法
    四大发明之活字印刷——面向对象思想的胜利
    每个IT人都应当拥有的30条技能
    面向对象的本质是什么?
    数据库设计规范 zhuan
    翻动100万级的数据 —— 只需几十毫秒 转
    程序员发展十分重要的12条日常习惯
  • 原文地址:https://www.cnblogs.com/yejinru/p/2414165.html
Copyright © 2011-2022 走看看