zoukankan      html  css  js  c++  java
  • CODEVS 3139 栈练习3

    3139 栈练习3

     

     时间限制: 2 s
     空间限制: 128000 KB
     题目等级 : 黄金 Gold
    题目描述 Description

    比起第一题,本题加了另外一个操作,访问栈顶元素(编号3,保证访问栈顶元素时或出栈时栈不为空),现在给出这N此操作,输出结果。

    输入描述 Input Description

    N

    N次操作(1入栈 2出栈 3访问栈顶)

    输出描述 Output Description

    K行(K为输入中询问的个数)每次的结果

    样例输入 Sample Input

    6

    1  7

    3

    2

    1  9

    1  7

    3

    样例输出 Sample Output

    7

    7

    数据范围及提示 Data Size & Hint

     对于50%的数据 N≤1000 入栈元素≤200

     对于100%的数据 N≤100000入栈元素均为正整数且小于等于10^4 


    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,x,y,top=0,f[100010]; int main() { cin>>n; for (int i=1;i<=n;i++) { cin>>x; if (x==1) { cin>>y; top++; f[top]=y; } if (x==2) { f[top]=0; top--; } if (x==3) { cout<<f[top]<<endl; } } return 0; }
  • 相关阅读:
    合并hive/hdfs小文件
    NoSql图形数据库
    mysql分表
    查看带宽使用
    mysql中间件kingshard
    centos7安装docker
    nginx的proxy_pass路径转发规则最后带/问题
    centos关闭邮件提醒
    JOSN转列格式(csv文件)
    Android 常见对话框
  • 原文地址:https://www.cnblogs.com/xiaoqi7/p/5379984.html
Copyright © 2011-2022 走看看