• UVa 514 铁轨


    题意:

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        int num[1007];
        int kase = 0;
        while(scanf("%d", &n) != EOF && n != 0)
        {
            while(scanf("%d", &num[0]) && num[0] != 0){
                stack<int> s1;
                num[1] = num[0];
                for(int i = 2; i <= n; i++){
                    scanf("%d", num+i);
                }
                int ok = 0;
                int A = 1, B = 1;
                while(B <= n){
                    if(A == num[B]){A++; B++;}
                    else if(!s1.empty() && s1.top() == num[B]){s1.pop(); B++;}
                    else if(A <= n) s1.push(A++);
                    else {ok =0; break;};
                }
                if(ok) printf("Yes
    ");
                else printf("No
    ");
            }
            printf("
    ");
        }
    }
  • 相关阅读:
    IO流
    泛型类
    自动打包&解包:auto-boxing&unboxing
    Map接口
    如何选择数据结构
    Compareable接口
    List常用算法
    equals和==
    List接口
    set接口
  • 原文地址:https://www.cnblogs.com/Jadon97/p/7168706.html
Copyright © 2020-2023  润新知