zoukankan      html  css  js  c++  java
  • 银行业务队列简单模拟(队列queue)

    设某银行有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 15
    
     代码:
     
    import java.util.*;
    
    public class Main{
          public static void main(String[] args) {
                Scanner scan=new Scanner(System.in);
                ArrayDeque<Integer> q1=new ArrayDeque<Integer>();
                ArrayDeque<Integer> q2=new ArrayDeque<Integer>();
                int n=scan.nextInt();
                while(n-->0){
                      int num=scan.nextInt();
                      if(num%2==1)  q1.offer(num);
                      else q2.offer(num);
                }
                while(!q1.isEmpty()){
                      int cnt=2,k=0;
                      while(cnt-->0 && !q1.isEmpty()){
                           if(k++>0) System.out.print(" ");
                           System.out.print(q1.poll());
                      }
                      if(!q2.isEmpty()){
                           System.out.print(" "+q2.poll());
                      }
                      if(!q2.isEmpty()||!q1.isEmpty()) System.out.print(" ");//只有队列q1或者q2不空时再加空格
                }
                int k=0;
                while(!q2.isEmpty()){
                      if(k++>0) System.out.print(" ");
                      System.out.print(q2.poll());
                }
        }
    }
  • 相关阅读:
    Tensorflow CIFAR10 (二分类)
    2018年阿里巴巴重要开源项目汇总
    环境变量备份
    ubuntu Qt5 librealsense opencv
    ubuntu16.04 qt opencv3.4
    时间作为文件名
    ubuntu16.04 安装opencv3
    Visual studio 2015/2017 opencv3.4 kineck2.0 osg realsense配置
    开源监控系统整合Nagios+Cacti+Nconf详解
    nagios系列(八)之nagios通过nsclient监控windows主机
  • 原文地址:https://www.cnblogs.com/qdu-lkc/p/12207228.html
Copyright © 2011-2022 走看看