蓝桥 ADV-233 算法提高 队列操作 【STL】

  算法提高 队列操作  
时间限制:1.0s   内存限制:256.0MB
    
问题描述
  队列操作题。根据输入的操作命令,操作队列(1)入队、(2)出队并输出、(3)计算队中元素个数并输出。
输入格式
  第一行一个数字N。
  下面N行,每行第一个数字为操作命令(1)入队、(2)出队并输出、(3)计算队中元素个数并输出。
输出格式
  若干行每行显示一个2或3命令的输出结果。注意:2.出队命令可能会出现空队出队(下溢),请输出“no”,并退出。
样例输入
7
1 19
1 56
2
3
2
3
2
样例输出
19
1
56
0
no
数据规模和约定
  1<=N<=50

题目链接:

  http://lx.lanqiao.cn/problem.page?gpid=T417

题目大意:

  模拟一个队列。1插入元素x,2取出元素并输出,3统计队列大小。注意2的越界

题目思路:

  【STL】

  STL直接上queue。

 1 /****************************************************
 2     
 3     Author : Coolxxx
 4     Copyright 2017 by Coolxxx. All rights reserved.
 5     BLOG : http://blog.csdn.net/u010568270
 6     
 7 ****************************************************/
 8 #include<bits/stdc++.h>
 9 #pragma comment(linker,"/STACK:1024000000,1024000000")
10 #define abs(a) ((a)>0?(a):(-(a)))
11 #define lowbit(a) (a&(-a))
12 #define sqr(a) ((a)*(a))
13 #define mem(a,b) memset(a,b,sizeof(a))
14 const double eps=1e-8;
15 const int J=10000;
16 const int mod=1000000007;
17 const int MAX=0x7f7f7f7f;
18 const double PI=3.14159265358979323;
19 const int N=10004;
20 using namespace std;
21 typedef long long LL;
22 double anss;
23 LL aans;
24 int cas,cass;
25 int n,m,lll,ans;
26 int main()
27 {
28     #ifndef ONLINE_JUDGE
29 //    freopen("1.txt","r",stdin);
30 //    freopen("2.txt","w",stdout);
31     #endif
32     int i,j,k;
33     int x,y,z;
34 //    for(scanf("%d",&cass);cass;cass--)
35 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
36 //    while(~scanf("%s",s))
37 //    while(~scanf("%d",&n))
38     scanf("%d",&n);
39     if(1)
40     {
41         queue<int>q;
42         while(!q.empty())q.pop();
43         for(i=1;i<=n;i++)
44         {
45             scanf("%d",&x);
46             if(x==1)
47             {
48                 scanf("%d",&y);
49                 q.push(y);
50             }
51             else if(x==2)
52             {
53                 if(q.empty()){puts("no");break;}
54                 printf("%d
",q.front());
55                 q.pop();
56             }
57             else if(x==3)
58             {
59                 printf("%d
",q.size());
60             }
61         }
62     }
63     return 0;
64 }
65 /*
66 //
67 
68 //
69 */
View Code
原文地址:https://www.cnblogs.com/Coolxxx/p/6671369.html