两个队列 一个队列放优先级,一个队列放优先级里的数,顺便用的了map 确定数在哪个优先级里
1 #include <iostream> 2 using namespace std; 3 #include<string.h> 4 #include<stdio.h> 5 #include<queue> 6 #include<map> 7 int main() 8 { 9 10 int t,m,i,n,add=0; 11 while(cin>>t,t) 12 { 13 cout<<"Scenario #"<<++add<<endl; 14 map<int,int>a; 15 for(i=0;i<t;i++) 16 { 17 cin>>m; 18 while(m--) 19 { 20 cin>>n; 21 a[n]=i; 22 } 23 } 24 queue<int > team; 25 queue<int > team1[1010]; 26 char CNM[10]; 27 int mmp; 28 while(cin>>CNM) 29 { 30 if(CNM[0]=='S') 31 break; 32 else if(CNM[0]=='D') 33 { 34 int t=team.front(); 35 cout<<team1[t].front()<<endl; 36 team1[t].pop(); 37 if(team1[t].empty()) 38 team.pop(); 39 } 40 else if(CNM[0]=='E') 41 { 42 cin>>mmp; 43 int zxc=a[mmp]; 44 if(team1[zxc].empty()) 45 team.push(zxc); 46 team1[zxc].push(mmp); 47 } 48 } 49 cout<<endl; 50 } 51 return 0; 52 }