首页 > 其他分享 >7-6 银行业务队列简单模拟

7-6 银行业务队列简单模拟

时间:2023-01-29 14:23:57浏览次数:43  
标签:temp 队列 s2 s1 int flag 银行业务 printf 模拟

#include<stdio.h>
#include<stack>
#include<queue>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
int flag=1;
queue<int>s1,s2;//奇数s1a窗口
scanf("%d",&n);
int i;
int data;
for(i=0;i<n;i++)
{
scanf("%d",&data);
if(data%2==0)
{
s2.push(data);
}
else s1.push(data);
}
int count1=0;
int temp;
while(s1.empty()==0&&s2.empty()==0)
{
if(count1==2)
{
count1=0;
temp=s2.front();
s2.pop();
if(flag==1)
{
printf("%d",temp);
flag=0;
}
else printf(" %d",temp);
}
else{
count1++;
temp=s1.front();
s1.pop();
if(flag==1)
{
printf("%d",temp);
flag=0;
}
else printf(" %d",temp);
}
}
while(s1.empty()==0){
//TODO
temp=s1.front();
s1.pop();
if(flag==1)
{
printf("%d",temp);
flag=0;
}
else printf(" %d",temp);
}
while(s2.empty()==0){
//TODO
temp=s2.front();
s2.pop();
if(flag==1)
{
printf("%d",temp);
flag=0;
}
else printf(" %d",temp);
}
}

标签:temp,队列,s2,s1,int,flag,银行业务,printf,模拟
From: https://www.cnblogs.com/momo666/p/17072558.html

相关文章