PTA银行业务队列简单模拟c++——山东科技大学

#include<bits/stdc++.h>
using namespace std;
queue<int>A,B;
void init()
{
    
    
    int n,a;
    cin>>n;
    for(int i=0;i<n;i++)
    {
    
    
        cin>>a;
        a%2?A.push(a):B.push(a);
    }
}
void solve()
{
    
    
    int x=0;
    while(A.size()||B.size())
    {
    
    
        if(A.size())
        {
    
    
            if(x)cout<<' ';
            cout<<A.front();
            A.pop();
            x=1;
        }
        if(A.size())
        {
    
    
            if(x)cout<<' ';
            cout<<A.front();
            A.pop();
            x=1;
        }
        if(B.size())
        {
    
    
            if(x)cout<<' ';
            cout<<B.front();
            B.pop();
            x=1;
        }
    }
}
int main()
{
    
    
    init();
    solve();
}

猜你喜欢

转载自blog.csdn.net/scorpion_legend/article/details/109131509