zoukankan      html  css  js  c++  java
  • 案例3-1.9 银行业务队列简单模拟 (25分)

    设某银行有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



    #include<iostream>
    
    using namespace std;
    #define max 1005
    void print(int i)//打印函数
    {
        static int flag = 0;//下一次打印的时候直接使用上一次的flag的值,
        if(flag)
            printf(" %d",i);
        else
            printf("%d",i);
        flag++;
    }
    int main()
    {
        int a[max]={0};
        int b[max]={0};
    
        int atail=0, ahead = 0;//队头和队尾
        int bhead = 0, btail = 0;
        int n,temp;
        scanf("%d",&n);
    
        for(int i=0;i<n;i++)
        {
            scanf("%d",&temp);
    
            if(temp%2)//奇数读入a,否则b
                a[atail++]= temp;
            else
                b[btail++]=temp;
        }
    
        while(ahead<atail || bhead < btail)
        {
            if(ahead < atail)//a队列输出2个b输出一个
                print(a[ahead++]);
            if(ahead < atail)
                print(a[ahead++]);
            if(bhead < btail)
                print(b[bhead++]);
        }
    
        return 0;
    }
  • 相关阅读:
    求斐波那契数列的第n项
    八大经典排序算法
    [BZOJ 3083] 遥远的国度
    [BZOJ 3306] 树
    [SCOI 2010] 序列操作
    [AHOI 2013] 差异
    [USACO2006 DEC] Milk Patterns
    [JSOI 2007] 字符加密
    [BZOJ 2588] Count on a tree
    [NOIP 2018 Day1] 简要题解
  • 原文地址:https://www.cnblogs.com/qinmin/p/12499068.html
Copyright © 2011-2022 走看看