Title Description
Group queue is a queue structure in a common queue structure, has a wide application in many places. Group refers to an element queues are grouped together within the queue. Set of queues includes two commands:
1, ENQUEUE, means that when there is a new element into the queue, it first retrieves whether there are elements of the same group already exists, if there is a new element in the last row of the same group, if not then inserted into the end of the queue.
2, DEQUEUE, showing elements dequeue the queue head
3, STOP, stop operation
C ++ is recommended to use the queue object comes queue, programming more convenient
Entry
A first input line t (t <= 10), represents a number of queue groups
Value of the line number of elements and a second input of the first group
Value of the line number of elements and a third input of the second group
End group to enter t so defined after the element group, a plurality of input operation start command (<200), an empty set of queues operate the ENQUEUE 100 such as input, element 100 represents the enqueue
Export
DEQUEUE a team element
Sample input
Sample Output
prompt
#include <the iostream> #include <Queue> #include <Map> the using namespace STD; int main () { int T; CIN >> T; int value; Map < int , int > MEM; /// Map Providing key- -value map, where each key (101,102,103) are of value 1, (201, 202) are of value 2 int in Flag = 1 ; int Number; Queue < int > que [T] ; Queue < int > Output; for (int i=0;i<T;i++) { cin>>number; while(number--) { cin>>value; mem[value]=i; } } string oper; while(cin>>oper&&oper!="STOP") { if(oper=="ENQUEUE") { cin>>value; for(int i=0; I <T; I ++ ) { IF (que [I] .empty () || MEM [que [I] .front ()] == MEM [value]) /// If the queue is empty or the key corresponding to value and a value of the queue head of the queue is the same as the team { que [I] .push (value); BREAK ; } } } the else IF (Oper == " DEQUEUE " ) { for ( int I = 0 ; I <T ; I ++ ) { IF (! que [I] .empty ()) { output.push (que [I] .front ()); que [I] .pop (); BREAK ; } } } }///存起来用output队列输出 while(!output.empty()) { if(flag==1) { flag=0; cout<<output.front(); } else cout<<" "<<output.front(); output.pop(); } cout<<endl; return 0; }