DS queue ---- Bank simple simulation

Title Description

There is provided a bank A, B two service windows and service processing speed is not the same, wherein A is 2 times the processing speed of the window B in the window - i.e., when the completion of each window A process customer 2, B processed window 1 a customer. Given the sequence of Customers Bank, please complete the order by business customers of the output sequence. Assuming no customer has to consider the time interval arrives, and when different windows simultaneously processed two customers, A customer priority output window.

 

Entry

Line input is a positive integer, wherein the first number N ( ≤1000) the total number of customers, followed by N-bit customer number. Odd numbered window A customer needs to conduct business, an even number of customers went to B window. Between numbers separated by a space.

 

Export

Press transaction completion sequence output from the customer number. Between numbers separated by spaces, but can not have an extra space after the last number.

 

Sample input

8 2 1 3 9 4 11 13 15

Sample Output

1 3 2 9 11 4 13 15

prompt

#include<iostream>
#include<queue>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int *a=new int[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    queue<int>A;
    queue<int>B;
    for(int i=0;i<n;i++)
    {
        if(a[i]%2!=0)
            A.push(a[i]);
        else
            B.push(a[i]);
    }
    int myclock=1;
    int tag=0;
    while(!A.empty()||!B.empty())
    {
        if(!A.empty()&&tag==0)
        {
            cout<<A.front();
            A.pop();
            tag++;
        }
        else if(!A.empty()&&tag!=0)
        {
            cout<<" "<<A.front();
            A.pop();
        }
        if(!B.empty()&&tag==0&&myclock%2==0)
        {
            cout<<B.front();
            B.pop();
            tag++;
        }
        else if(!B.empty()&&tag!=0&&myclock%2==0)
        {
            cout<<" "<<B.front();
            B.pop();
        }
        myclock++;
    }
    delete []a;
    return 0;
}

Guess you like

Origin www.cnblogs.com/SZU-DS-wys/p/12180718.html