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

来源:互联网 发布:linux man命令怎么用 编辑:程序博客网 时间:2024/05/02 01:49

  算法提高 队列操作  
时间限制: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。



/****************************************************Author : CoolxxxCopyright 2017 by Coolxxx. All rights reserved.BLOG : http://blog.csdn.net/u010568270****************************************************/#include<bits/stdc++.h>#pragma comment(linker,"/STACK:1024000000,1024000000")#define abs(a) ((a)>0?(a):(-(a)))#define lowbit(a) (a&(-a))#define sqr(a) ((a)*(a))#define mem(a,b) memset(a,b,sizeof(a))const double eps=1e-8;const int J=10000;const int mod=1000000007;const int MAX=0x7f7f7f7f;const double PI=3.14159265358979323;const int N=10004;using namespace std;typedef long long LL;double anss;LL aans;int cas,cass;int n,m,lll,ans;int main(){#ifndef ONLINE_JUDGE//freopen("1.txt","r",stdin);//freopen("2.txt","w",stdout);#endifint i,j,k;int x,y,z;//for(scanf("%d",&cass);cass;cass--)//for(scanf("%d",&cas),cass=1;cass<=cas;cass++)//while(~scanf("%s",s))//while(~scanf("%d",&n))scanf("%d",&n);if(1){queue<int>q;while(!q.empty())q.pop();for(i=1;i<=n;i++){scanf("%d",&x);if(x==1){scanf("%d",&y);q.push(y);}else if(x==2){if(q.empty()){puts("no");break;}printf("%d\n",q.front());q.pop();}else if(x==3){printf("%d\n",q.size());}}}return 0;}/*////*/


0 0
原创粉丝点击