zoukankan      html  css  js  c++  java
  • poj1363

    栈模拟

    View Code
    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    #include <stack>
    using namespace std;
    
    #define maxn 1005
    
    int n;
    int f[maxn];
    
    void input()
    {
        for (int i = 1; i < n; i++)
            scanf("%d", &f[i]);
    }
    
    bool ok()
    {
        stack<int> stk;
        int temp = 1;
        for (int i = 0; i < n; i++)
        {
            while (temp <= f[i])
                stk.push(temp++);
            int x = stk.top();
            stk.pop();
            if (x != f[i])
                return false;
        }
        return true;
    }
    
    int main()
    {
        //freopen("t.txt", "r", stdin);
        while (scanf("%d", &n), n)
        {
            while (scanf("%d", &f[0]), f[0])
            {
                input();
                if (ok())
                    puts("Yes");
                else
                    puts("No");
            }
            puts("");
        }
        return 0;
    }
  • 相关阅读:
    内存对齐
    类和对象
    C++ 各种继承方式的类内存布局
    静态变量static
    程序内存布局
    String类
    C++与C的区别
    命名空间
    C
    D
  • 原文地址:https://www.cnblogs.com/rainydays/p/2866060.html
Copyright © 2011-2022 走看看