银行业务队列简单模拟

设某银行有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
 1 #include <iostream>
 2 #include <queue>
 3 using namespace std;
 4 
 5 int main() {
 6     int num;
 7     cin >> num;
 8     queue<int> a,b,q;
 9     while(num--) {
10         int temp;
11         cin >>    temp;
12         (temp%2==0)? b.push(temp) : a.push(temp);
13     }
14     int flag = 0;
15     while(!a.empty() && !b.empty()) {
16         if(flag!=0) printf(" ");
17         if(flag==0) flag=1;
18         cout << a.front();
19         a.pop();
20         if(!a.empty()) {
21             if(flag!=0) printf(" ");
22             if(flag==0) flag=1;
23             cout << a.front();
24             a.pop();
25         }
26         if(flag!=0) printf(" ");
27         if(flag==0) flag=1;
28         cout << b.front();
29         b.pop();
30     }
31     while(!a.empty()) {
32         if(flag!=0) printf(" ");
33         if(flag==0) flag=1;
34         cout << a.front();
35         a.pop();
36     }
37     while(!b.empty()) {
38         if(flag!=0) printf(" ");
39         if(flag==0) flag=1;
40         cout << b.front();
41         b.pop();
42     }
43     return 0;
44 }
原文地址:https://www.cnblogs.com/i-chase/p/13185491.html