Home > Back-end >  7-4 simple banking queue simulation (25 points)
7-4 simple banking queue simulation (25 points)

Time:04-26

Set up A bank with A, B two business window, and the speed of the processing business, including A window processing speed is 2 times B window - that is, when A window after each processing two customers, B window handle one customer, reach the bank customers given sequence, please according to the business to complete the order in which the output sequence customers, assume that does not consider the customer time interval has arrived, and when the different window handle the two customers at the same time, A customer first output window,

Input format:
Input is A positive integer, of which the first number N (1000) or less for the total number of customers, followed by N A customer number, number is an odd number of customers to A window to handle the business need, and to an even number of customers, to B window, separated by Spaces between Numbers,

The output format:
Processing to complete the order in which the output of the business customer's Numbers, separated by Spaces between Numbers, but in the end a number later can't have extra Spaces,

Input the sample:
8 9 2 1 3 4 11 of 13 15
The output sample:
1 2 3 9 11 4 13 to 15

CodePudding user response:

Int InitQueue (SqQueue & amp; Q)
{
Q.b ase=new int [MAXSIZE];
if(! Q.b ase)
Return OVERFLOW;
Q.f ront=Q.r ear=0;
return OK;
}
Int to DeQueue (SqQueue & amp; Q, int & amp; E)
{
If (Q.f ront==Q.r ear)
return ERROR;
E=Q.b ase [Q.f ront];
Q.f ront=(Q.f ront + 1) % MAXSIZE;
return OK;
}
Arr void Print (int * and an int n)
{
Coutfor(int i=1; iCout<" "& lt; }

CodePudding user response:

#include
#include
# define MAX 1000
# define the error - 1
Typedef struct node {
Int the customer (MAX);
Int rear;
Int the front;
} the queue;
Void the add (queue * q, int item)
{
If ((q - & gt; Rear MAX + 1) %==q - & gt; Front)
{
Printf (" queue full \ n ");
return;
}
Q - & gt; Rear=(q - & gt; Rear + 1) % MAX;
Q - & gt; The customer [q - & gt; rear]=item;
}
Int isempty (queue * q)
{
Return the q - & gt; The front==q - & gt; The rear;
}
Int deleteq (queue * q)
{
If (isempty (q))
{
Printf (" team empty \ n ");
Return the error;
}
Q - & gt; The front=(q - & gt; Front + 1) % MAX;
Return the q - & gt; The customer/q - & gt; front;
}
Void initial (queue * q)
{
Q - & gt; Rear=q - & gt; The front=0;
}
Int main ()
{
Int N, I, number, flag;
The queue A, B;
Initial (& amp; A);
Initial (& amp; B);
The scanf (" % d ", & amp; N);
For (I=0; I & lt; N; I++)
{
The scanf (" % d ", & amp; Number);
If (number % 2)//odd in A
Add (& amp; A, number);
The else
Add (& amp; B, the number);//even in B
}
Flag=0;//marks the first customer
while (! Isempty (& amp; A) & amp; & ! Isempty (& amp; B))//A and B are not empty interval output
{
If (flag==0)
{
Printf (" % d ", deleteq (& amp; A));
Flag=1;
}
The else
Printf (" % d ", deleteq (& amp; A));
if (! Isempty (& amp; A))
Printf (" % d ", deleteq (& amp; A));
Printf (" % d ", deleteq (& amp; B));
}
while (! Isempty (& amp; A))
{
If (flag==0)
{
Printf (" % d ", deleteq (& amp; A));
Flag=1;
}
The else
Printf (" % d ", deleteq (& amp; A));
}
while (! Isempty (& amp; B))
{
if (! Flag)
{
Printf (" % d ", deleteq (& amp; B));
Flag=1;
}
The else
Printf (" % d ", deleteq (& amp; B));
}
printf("\n");
}

CodePudding user response:

#include
#include

Void Print (int);

Int main () {
int n;
The scanf (" % d ", & amp; n);
Int a, [1001].
For (int k=0; K{
The scanf (" % d ", & amp; A, [k]).
}
Int I=0, j=0;
While (i{
for(; iIf (1==a [I] % 2)
{

Print (a [i++]);
break;
}
for(; i{
If (1==a [I] % 2)
{
Print (a [i++]);
break;
}
}
for(; J{
If (0==a [j] % 2)
{
Print (a [j++]);
break;
}
}
}

return 0;
}
Void Print (int num) {
Static int flag=0;
If (flag)
printf(" ");
The else flag=1;

Printf (" % d ", num);

}

CodePudding user response:


#include
#include
#include
Int main ()
{
Int A, [1000].
Int B [1000];
Int N;
Int a=0, b=0, temp.
The scanf (" % d ", & amp; N);
for(int i=0; iThe scanf (" % d ", & amp; Temp);
If (temp % 2==1)
A, (+)=temp.
The else
B [b++]=temp;
}
int i=0, j=0;
If (a & gt; 1) {//A, there are more than two people, two output
Printf (" % d % d ", A [0], A [1]).
I=2;
}
Else if (a & gt; 0)//A, there are more than one, output A
Printf (" % d ", A [i++]);
Else if (b & gt; Nobody 0)//A, B someone, output A B
Printf (" % d, B [j++]);

If (j==0)//output A no output B, to control the output of A set of output A B
Printf (" % d, B [j++]);

While (I & lt; A. & amp; & J & lt; B) {
If (I + 1 & lt; A) {
Printf (" % d % d ", A [I], A [I + 1));
I +=2;
}
The else
Printf (" % d ", A [i++]);
Printf (" % d, B [j++]);
}
While (I & lt; A)
Printf (" % d ", A [i++]);
While (j & lt; B)
Printf (" % d, B [j++]);
}
  • Related