#include #include #include #define DBG(x) FILE *input; int t[1000000]; int n; class ele { public: int e; struct ele *next; } *root,*last; //ele* team[1000]; typedef ele* Pele; Pele team[1000]; int read_case() { int i,j,k,p; fscanf(input,"%d",&n); if (n==0) return 0; for (i=0;i%s",s);); if (strcmp(s,"ENQUEUE")==0) { fscanf(input,"%d",&e); if (team[t[e]]!=NULL) { /* beim team anhaengen */ el=new ele(); el->next=team[t[e]]->next; el->e=e; team[t[e]]->next=el; team[t[e]]=el; } else { /* hinten */ if (root==NULL) { el=new ele(); root=last=el; el->next=NULL; el->e=e; team[t[e]]=el; } else { el=new ele(); el->next=NULL; el->e=e; last->next=el; last=el; team[t[e]]=el; } } } else if (strcmp(s,"DEQUEUE")==0) { ele *temp; int e; e=root->e; printf("%d\n",e); if (team[t[e]]==root) team[t[e]]=NULL; temp=root->next; delete root; root=temp; } else break; } } int main() { input=fopen("team.in","r"); assert(input!=NULL); while(read_case()) solve_case(); fclose(input); return 0; }