zoukankan      html  css  js  c++  java
  • 3185 队列练习 1

    3185 队列练习 1

     

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

    给定一个队列(初始为空),只有两种操作入队和出队,现给出这些操作请输出最终的队头元素。 操作解释:1表示入队,2表示出队

    输入描述 Input Description

    N(操作个数)
    N个操作(如果是入队则后面还会有一个入队元素)
    具体见样例(输入保证队空时不会出队)

    输出描述 Output Description

    最终队头元素,若最终队空,输出”impossible!”(不含引号)

    样例输入 Sample Input

    3
    1 2
    1 9
    2

    样例输出 Sample Output

    9

    数据范围及提示 Data Size & Hint

    对于100%的数据 N≤1000 元素均为正整数且小于等于100

     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 int a[1001];
     5 int b[1001];
     6 int c[1001];
     7 int main()
     8 {
     9     int n;
    10     cin>>n;
    11     for(int i=1;i<=n;i++)
    12      {
    13          cin>>a[i];
    14          if(a[i]==1)
    15           {
    16               cin>>b[i]; 
    17           }
    18       } 
    19     int head=0,tail=0; 
    20     for(int i=1;i<=n;i++)
    21      {
    22          if(a[i]==1)
    23           {
    24               tail++;
    25               c[tail]=b[i];
    26           }
    27           else if(a[i]==2)
    28            {
    29                head++;
    30            }
    31      }
    32      if(head==tail)
    33      {
    34          cout<<"impossible!";
    35          return 0;
    36      }
    37      cout<<c[head+1];
    38 }
  • 相关阅读:
    elk+redis
    elk7.4+filebeat收集日志
    k8s-高可用集群实现(keepalived+haproxy)
    k8s-高可用集群实现(keepalived)
    keepalived(双主模式)+haproxy+mysql_slave
    haproxy-实现mysql多slave读负载均衡
    MySQL数据库的配置
    前端模块化(AMD和CMD、CommonJs)
    一分钟配置jdk
    MySQL基础语法
  • 原文地址:https://www.cnblogs.com/lyqlyq/p/6665246.html
Copyright © 2011-2022 走看看