Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include <iostream>
- #include <queue>
- struct Node{
- int member;
- short int name;
- Node *next;
- }*head,*nowAt,*last,*temp;
- int main(){
- string op;
- int opOn;
- short int opIn;
- int n,t;
- int LINE = 0;
- short int groupSize;
- short int groupBelong[1000050] ={0};
- queue <int> group[1010];
- while (cin >> n){
- head = new Node;
- for (int i=0;i<1005;++i)
- while (!group[i].empty())
- group[i].pop();
- cout << "Line #" << ++LINE << '\n';
- for (int i=1;i<=n;++i){
- cin >> groupSize;
- while (groupSize--){
- cin >> t;
- groupBelong[t] = i;
- }
- }
- nowAt = head;
- last = head;
- head->next = 0;
- cin >> op >> opOn; //�o�榳�i��X�ơA�p�G����ܾ��T����stop����
- if (!groupBelong[opOn]){
- nowAt->name = 0;
- nowAt->member = opOn;
- }
- else{
- nowAt->name = groupBelong[opOn];
- group[groupBelong[opOn]].push(opOn);
- }
- while (cin >> op){
- if (op == "STOP")
- break;
- else if (op == "ENQUEUE"){
- cin >> opOn;
- opIn = groupBelong[opOn];
- if (head->name == -1){
- head->name = groupBelong[opOn];
- if (opIn){
- group[opIn].push(opOn);
- }
- else{
- head->member = opOn;
- }
- continue;
- }
- if (!opIn){
- nowAt = last;
- nowAt->next = new Node;
- nowAt = nowAt->next;
- nowAt->name = 0;
- nowAt->member = opOn;
- last = nowAt;
- last->next = 0;
- }
- else{
- if (group[opIn].empty()){
- nowAt = last;
- nowAt->next = new Node;
- nowAt = nowAt->next;
- nowAt->next = 0;
- nowAt->name = groupBelong[opOn];
- group[opIn].push(opOn);
- last = nowAt;
- }
- else{
- group[opIn].push(opOn);
- }
- }
- }
- else{
- nowAt = head;
- if (!head->name){
- cout << head->member << '\n';
- head = head->next;
- delete nowAt;
- }
- else{
- opIn = head->name;
- cout << group[opIn].front() << '\n';
- group[opIn].pop();
- if (group[opIn].empty()){
- head = head->next;
- delete nowAt;
- }
- }
- if (!head){
- head = new Node;
- head->next = 0;
- head->name = -1;
- last = head;
- }
- }
- }
- nowAt = head;
- while (nowAt != last){
- temp = nowAt;
- nowAt = nowAt->next;
- delete temp;
- }delete last;
- for (int i=0;i<1000050;++i)
- groupBelong[i] = 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement