Home Article Practice c++ Team Queue

c++ Team Queue

2023-01-15 12:58  views:652  source:6660    

#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
queue<int>dd,xd[n];
vector<int>d[n];
for(int i=0;i<n;i++)
{
int k;
cin>>k;
for(int j=0;j<k;j++)
{
int t;
cin>>t;
d[i].push_back(t);
}
}
for(int i=0;i<m;i++)
{
string s;
cin>>s;
if(s[0]=='E'){
int ren;
cin>>ren;
int dw=-1;
for(int ii=0;ii<n&&dw==-1;ii++)
{
for(int ij=0;ij<d[ii].size()&&dw==-1;ij++)
if(d[ii][ij]==ren)dw=ii;
}
if(xd[dw].empty())dd.push(dw);
xd[dw].push(ren);
}
else{
int t=dd.front();
int r=xd[t].front();
cout<<r<<endl;
xd[t].pop();
if(xd[t].empty())dd.pop();
}
}
return 0;
}



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)