《数据结构编程实验》 2.4.5MANAGER
来源:互联网 发布:北方软件学院好考吗 编辑:程序博客网 时间:2024/05/17 23:25
题目大意:
模拟一个队列,按给出的输出列表输出第i个出队的元素,若队列为空则输出-1。
题目地址:
POJ 1281 ZOJ 1371 UVA 2514
题解:
纯模拟,但有多组数据,在这里被坑了。
#include <iostream>#include <cstdio>using namespace std;int f[10010],a[10000];int j,k,l,n,m,mp;int del(){ int i; if (k==1) { i=1; while (i<=mp) if (f[i]>0) {f[i]--;m++;if (m==a[l]) {printf("%d\n",i);l++;}return 0;} else i++; } else { i=mp; while (i>0) if (f[i]>0) {f[i]--;m++;if (m==a[l]) {printf("%d\n",i);l++;}return 0;} else i--; } m++; return 1;}int main(){ char c; int i; while (scanf("%d",&mp)!=EOF) { scanf("%d",&n); for (i=1;i<=mp;i++) f[i]=0; for (i=0;i<n;i++) scanf("%d",&a[i]); m=0; k=1; l=0; while (scanf("%c",&c)&&c!='e') { if (c=='a') {scanf("%d",&i);f[i]++;} if (c=='r') if (del()) if (m==a[l]) {printf("-1\n");l++;} if (c=='p') {scanf("%c%c",&c,&c);if (c=='2') k=2;else k=1;} } printf("\n"); } return 0;}
0 0
- 《数据结构编程实验》 2.4.5MANAGER
- 《数据结构编程实验》 2.4.1Gold Coins
- 《数据结构编程实验》 2.4.3Pascal Library
- 《数据结构编程实验》 2.4.2The 3n + 1 problem
- 《数据结构编程实验》 2.4.4Calendar个人见解,求指导
- 《数据结构实验5》--排序
- 《数据结构》实验5
- 数据结构实验5-2
- 数据结构实验5-递归
- 《数据结构编程实验》 1.1.1Financial Management
- 《数据结构编程实验》 1.2.1Doubles
- 《数据结构编程实验》 1.4.1Hangover
- 《数据结构编程实验》 1.4.2Humidex
- 《数据结构编程实验》 1.5.1Sum
- 《数据结构编程实验》 1.5.3Quicksum
- 《数据结构编程实验》 1.5.7Vertical Histogram
- 《数据结构编程实验》 1.5.8Ugly Numbers
- 《数据结构编程实验》 1.5.9排列
- 03-Struts2实现简单的登陆
- C语言程序设计(第二版)第4章例题
- 如何开始NUTCH
- arm架构和芯片厂商生产的芯片的区别
- 【.Net码农】C#中字符串转换为计算公式
- 《数据结构编程实验》 2.4.5MANAGER
- leetcode Pascal's Palindrome 2
- LeetCode 题目总结/分类
- Myeclipse自带spring包,以及使用方法!
- LeetCode-Atoi
- android系统架构解析
- nginx平滑重启
- SQLiteDatabase中query、insert、update、delete方法参数说明
- 编程语言的组成部分