卡塔库栗 • 1个月前
#include<iostream>
#include<stack>
#include<queue>
using namespace std;
queue<int> q;
stack<int> s,ts;
int k;
int main()
{
int n,a;
cin>>n;
while(n--)
{
cin>>a;
q.push(a);
}
cin>>k;
int t=0;
while(!q.empty())
{
s.push(q.front());
q.pop();
t++;
if(t==k)
{
while(!s.empty())
{
cout<<s.top()<<' ';
s.pop();
}
t=0;
}
}
while(!s.empty())
{
ts.push(s.top());
s.pop();
}
while(!ts.empty())
{
cout<<ts.top()<<' ';
ts.pop();
}
return 0;
}
评论:
请先登录,才能进行评论