zoukankan      html  css  js  c++  java
  • 判断——出栈能否实现

    #include<cstdio>
    #include<iostream>
    #include<stack>
     using namespace std;
     
    int main()
    {
         int n,i,k;
         int a[1010];
         stack<int> s;
         while(scanf("%d",&n),n)
         {
           while(scanf("%d",&a[1]))

             {
                 if(a[1]==0)

                 {

                     printf(" ");
                     break;
                 }
                 while(!s.empty())       //初始化清空栈
                     s.pop();

                 k=1;
                 for(i=2;i<=n;++i)
                     scanf("%d",&a[i]);
                for(i=1;i<=n;++i)
                 {
                     s.push(i);
                     if(i==a[k])
                     {
                        while(!s.empty()&&s.top()==a[k])
                         {
                             s.pop();
                             ++k;
                         }
                     }
                 }
                 if(s.empty())
                     printf("Yes ");
                 else
                     printf("No ");
             }
         }
         return 0;
    }

  • 相关阅读:
    鼠标移入图片放大效果
    搜索框
    将下拉菜单放入input框中
    轮播图2
    V-demo item.vue
    v-demo1 List.vue
    v-demo1 add.vue
    v-demo1 app.vue
    3D轮播图
    封装代码
  • 原文地址:https://www.cnblogs.com/aimqqroad-13/p/4437602.html
Copyright © 2011-2022 走看看