<数据结构学习与实验指导>3-3银行业务队列模拟/3-4一元多项式的乘法与加法运算

来源:互联网 发布:淘宝吉他店铺推荐 编辑:程序博客网 时间:2024/06/06 04:49

我的C++源代码:

#include<iostream>#include<queue>using namespace std;int main(){int n, temp, i = 0;//n顾客总数int flag = 0;queue<int>a, b;//a窗口,b窗口cin >> n;for (; i < n; i++){cin >> temp;if (temp % 2 == 1)a.push(temp);//编号为奇数去a窗口elseb.push(temp);//偶数去B}while (!a.empty() && !b.empty()){if (flag!=1){cout << a.front();//第一个顾客输出后无空格a.pop();//删除队列前部第一个元素flag = 1;}else{cout <<' '<< a.front();//后面元素有空格a.pop();}if (!a.empty()){cout <<' '<< a.front();//a窗口服务速度是B的两倍,a再输出一个顾客编号a.pop();}cout <<' '<< b.front();//输出b窗口的编号b.pop();}while (!a.empty())//输出剩余的a窗口顾客编号{if (!flag){printf("%d", a.front());a.pop();flag = 1;}else{printf(" %d", a.front());a.pop();}}while (!b.empty())//输出剩余的b窗口顾客编号{if (!flag){printf("%d", b.front());b.pop();flag = 1;}else{printf(" %d", b.front());b.pop();}}//system("pause");return 0;}


0 0
原创粉丝点击