当前位置:网站首页>7-3 银行业务队列简单模拟|PTA
7-3 银行业务队列简单模拟|PTA
2022-04-21 21:03:00 【所谓独醉】
7-3 银行业务队列简单模拟|PTA
设某银行有A、B两个业务窗口,且处理业务的速度不一样,其中A窗口处理速度是B窗口的2倍 —— 即当A窗口每处理完2个顾客时,B窗口处理完1个顾客。给定到达银行的顾客序列,请按业务完成的顺序输出顾客序列。假定不考虑顾客先后到达的时间间隔,并且当不同窗口同时处理完2个顾客时,A窗口顾客优先输出。
输入格式:
输入为一行正整数,其中第1个数字N(≤1000)为顾客总数,后面跟着N位顾客的编号。编号为奇数的顾客需要到A窗口办理业务,为偶数的顾客则去B窗口。数字间以空格分隔。
输出格式:
按业务处理完成的顺序输出顾客的编号。数字间以空格分隔,但最后一个编号后不能有多余的空格。
输入样例:
8 2 1 3 9 4 11 13 15
输出样例:
1 3 2 9 11 4 13 1
解
这道题没啥可说的,用一个队列就出来了,用C++写的
#include<bits/stdc++.h>
using namespace std;
int main ()
{
queue<int> res;
int n,a[1004], b[1001], peo, j = 0, k = 0;
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> peo;
if(peo %2 == 0)
b[k++] = peo;
else
a[j++] = peo;
}
int lenA = j, lenB = k;
j = 0;
k = 0;
for(j = 0; j < lenA && k < lenB; j++)
{
res.push(a[j]);
if(j % 2 == 1)
res.push(b[k++]);
}
if(j < lenA)
{
for( ; j < lenA; j++)
res.push(a[j]);
}
if(k < lenB)
{
for( ; k < lenB; k++)
res.push(b[k]);
}
while(!res.empty())
{
int t = res.front();
res.pop();
cout << t;
if(!res.empty())
cout << " ";
}
cout << endl;
return 0;
}
版权声明
本文为[所谓独醉]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_51126511/article/details/124328143
边栏推荐
- Importance of slip ring technology in machine operation
- 25. < tag array and simulation > - LT - 31 Next permutation + LT - 556 Next larger element III
- 使用foremost对磁盘镜像文件做数字取证
- 135、137、138、139和445端口解释及关闭方法
- MapReduce服务初体验
- Operation instructions for upgrading Tongda OA workflow
- Pretreatment problem
- win10使用技巧之关闭软件安装前的用户提示
- 预处理问题
- 3、MySQL Workbench 对表进行增删改查
猜你喜欢
![[embedded] about IAP + XMODEM receiving bin file from outside to upgrade the chip](/img/05/c69e3701bf80f03c8ec35c033944b1.png)
[embedded] about IAP + XMODEM receiving bin file from outside to upgrade the chip

Traceup | use project management software to help overcome procrastination

6、Qt使用MySQL例子

【嵌入式】关于IAP+Xmodem从外部接收bin文件对芯片进行升级学习记录

《ROS2机器人建模URDF》8.3动手创建一个移动机器人

迅为RK3568开发板交叉编译C程序

135、137、138、139和445端口解释及关闭方法

2、Failed to connect to MySQL Server 8.0.28 after 10 attempts

其它——CGI,FastCGI,WSGI,uWSGI,uwsgi一文搞懂

25. < tag array and simulation > - LT - 31 Next permutation + LT - 556 Next larger element III
随机推荐
VxWorks learning
10.2 concentration
工作流操作说明
其它——CGI,FastCGI,WSGI,uWSGI,uwsgi一文搞懂
Pytorch中的nn.AdaptiveAvgPool2d(output_size)简单介绍
《ROS2机器人建模URDF》8.4控制移动机器人轮子运动
Others - Analysis of redis and MySQL double write consistency scheme
APM 行业认知系列 - 十五
Go语言自学系列 | golang init函数
「內元宇宙」革命 聯載
What if the passage is full and you continue to send it inside?
Pytorch框架 || torch.nn.modules.Module(nn.Module)
4、MySQL Workbench创建访问用户
信息学奥赛一本通 1210:因子分解 | OpenJudge 1.13 22:因子分解
win10使用技巧之关闭软件安装前的用户提示
oracle管理 | 表空间权限管控
2022R2移动式压力容器充装考试练习题及在线模拟考试
其它——Siege压力测试工具使用
[azure application service] after azure function enables managed identity, error appears in PowerShell function: managedidentitycredential authentication failed
2022-04-21:给定一个包含 [0,n) 中不重复整数的黑名单 blacklist,写一个函数从 [0, n) 中返回一个不在 blacklist 中的随机整数