A bank has a and b two business windows, and the speed of processing business is not the same, where a window processing speed is twice times the b window-that is, when a window for each processing 2 customers, b window processing 1 customers. Given the sequence of customers arriving at the bank, output the customer sequence in the order in which the business is completed. Assuming that customers do not take into account the time interval, and when the different windows processed at the same time 2 customers, a window customer priority output. Input Format:
Enter a positive integer, where the 1th number n (≤1000) is the total number of customers followed by the number of n-digit customers. Odd-numbered customers need to go to window A to transact business, and even-numbered customers are going to window B. Numbers are separated by spaces. output Format:
The number of the customer is output in the order in which the business process is completed. Numbers are separated by spaces, but the last number cannot have extra spaces. Input Sample:
8 2 1 3 9 4 11 13 15
Output Sample:
1 3 2 9 11 4 13 15
Parsing: Two arrays are easy to resolve, but are course designed to examine the use of queues, so the queue is used in this topic.
#include <bits/stdc++.h> #define OVERFLOW-1 #define ERROR 0 #define FALSE 0 #define TRUE 1 #define OK 1 using NAMESP
Ace STD;
typedef int STATUS;
typedef int QELEMTYPE;
typedef struct QNODE {qelemtype data;
struct Qnode *next;
}qnode, *queueptr;
typedef struct QUEUE {QUEUEPTR front;
QUEUEPTR Rear;
}queue;
Status initqueue (Queue &q) {Q.front = (Qnode *) malloc (sizeof (Qnode)); if (!
Q.front) exit (OVERFLOW);
Q.front->next = NULL;
Q.rear = Q.front;
return OK;
Status destroyqueue (Queue &q) {Qnode *p = Q.front, *POSTP;
while (p) {POSTP = p->next;
Free (p);
p = POSTP;
} Q.front = Q.rear = NULL;
return OK;
Status clearqueue (Queue &q) {Qnode *p = q.front->next;
while (p) {Qnode *temp = p;
p = p->next;
Free (p);
} q.rear = Q.front;
Q.rear->next = NULL;
Status emptyqueue (Queue Q) {if (Q.front = = q.rear) return TRUE; return FALSE;
int Queuelength (Queue Q) {int len = 0;
Qnode *temp = q.front->next;
while (temp) {++len;
temp = temp->next;
return Len;
Status GetHead (Queue Q, Qelemtype &e) {if (Q.front = q.rear) return ERROR;
E = q.front->next->data;
return OK;
Status EnQueue (Queue &q, Qelemtype e) {queueptr p;
p = (Qnode *) malloc (sizeof (Qnode));
if (!p) exit (OVERFLOW); P->data = e;
P->next = NULL;
Q.rear->next = p;
Q.rear = p;
return OK;
Status dequeue (Queue &q, Qelemtype &e) {if (Q.front = q.rear) return ERROR;
Queueptr temp = q.front->next;
E = temp->data;
Q.front->next = temp->next;
if (q.rear = temp) q.rear = Q.front;
Free (temp);
return OK;
int main () {Queue Qa, Qb;
Initqueue (Qa);
Initqueue (QB);
int N, flag = 0;
scanf ("%d", &n);
for (int i = 0; i < n; ++i) {Qelemtype temp; scanf ("%d", &temp);
if (temp% 2 = 1) {EnQueue (Qa, temp);
else {EnQueue (Qb, temp);
for (int i = 0; I <= N; ++i) {Qelemtype temp; if (!
Emptyqueue (QA)) {dequeue (QA, temp);
if (flag = = 0) printf ("%d", temp);
else printf ("%d", temp);
flag = 1; if (i% 2 = 1 &&!)
Emptyqueue (QB)) {dequeue (QB, temp);
if (flag = = 0) printf ("%d", temp);
else printf ("%d", temp);
flag = 1;
}
}
}