T3185 队列练习1 codevs

http://codevs.cn/problem/3185/

题目描述 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 #include<algorithm>
 4 
 5 using namespace std;
 6 
 7 int a[10000+15];
 8 int N,x,m,head,tail;
 9 
10 int main()
11 {
12     cin>>N;
13     for(int i=1;i<=N;i++)
14     {
15         cin>>m;
16         if(m==1)
17         {
18             cin>>a[++tail];
19         }
20         if(m==2)
21         {
22             head++;    
23         }
24         
25     }
26     if(tail-head==0)
27         cout<<"impossible!";
28     else
29         cout<<a[head+1];
30     return 0;
31 }
——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
原文地址:https://www.cnblogs.com/Shy-key/p/6371727.html