3187 队列练习 3

3187 队列练习 3

 

时间限制: 1 s
空间限制: 128000 KB
题目等级 : 钻石 Diamond
 
 
 
题目描述 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
9

数据范围及提示 Data Size & Hint

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

 1 #include<iostream>
 2 #include<queue>
 3 using namespace std;
 4 queue<int>a;
 5 int main()
 6 {
 7     int n;
 8     cin>>n;
 9     for(int i=1;i<=n;i++)
10     {
11         int b;
12         cin>>b;
13         if(b==1)
14         {
15             int c;
16             cin>>c;
17             a.push(c);
18         }
19         else if(b==2)
20         {
21             a.pop();
22         }
23         else if(b==3)
24         {
25             cout<<a.front()<<endl;
26         }
27     }
28 /*    if(a.size()==0)
29     {
30         cout<<"impossible!";
31     }
32     else
33     {
34         cout<<a.front();
35     }*/
36     return 0;
37 }

 

posted @ 2017-03-28 18:49  自为风月马前卒  阅读(221)  评论(0编辑  收藏  举报

Contact with me