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;

    }

     

    编辑器加载中...

  • 相关阅读:
    Java的几种常用设计模式
    面向切面编程AOP
    面向过程编程、面向对象编程
    Java基础之集合与泛型
    Spring mvc中自定义拦截器
    Hibernate框架hibernate.cfg.xml配置文件,配置自动生成表结构策略。
    Notepad++打开xml文件显示crlf的问题
    java框架
    潜龙博客地址
    联通
  • 原文地址:https://www.cnblogs.com/yejinru/p/2414165.html
Copyright © 2011-2022 走看看