Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- struct node
- {
- char value;
- node *link;
- };
- int main()
- {
- int group;
- cin >> group;
- vector <vector<char>> customer(group);
- int i,j,member;
- char cust;
- for(i=0; i<group; ++i)
- {
- cin >> member;
- for(j=0; j<member; ++j)
- {
- cin >> cust;
- customer[i].push_back(cust);
- }
- }
- string status;
- node *head = NULL, *temp, *hold, *brief;
- int pos = 200;
- bool same = false;
- while(!cin.eof())
- {
- cin >> status;
- if(status == "enqueue")
- {
- cin >> cust;
- if(head == NULL)
- {
- hold = new node();
- hold->value = cust;
- head = hold;
- temp = hold;
- brief = hold;
- }
- else
- {
- // check if the input is repeated
- // if repeated the don't care
- while(brief != NULL)
- {
- if(cust != brief->value)
- same = true;
- brief = brief->link;
- }
- brief = head;
- if(same == true)
- {
- // check customer group number
- for(i=0; i<group; ++i)
- for(j=0; j<customer[i].size(); ++j)
- if(cust == customer[i][j])
- pos = i;
- // if not in any group
- if(pos > group)
- {
- hold = new node();
- hold->value = cust;
- temp->link = hold;
- temp = temp->link;
- }
- else if(pos <= group) // if in group
- {
- hold = new node();
- hold->value = cust;
- while(brief != NULL)
- {
- for(i=0; i<group; ++i)
- {
- for(j=0; j<customer[i].size(); ++j)
- {
- if(brief->value == customer[i][j])
- {
- if(pos == i)
- {
- // cout << "test" << endl;
- hold->link = temp;
- brief->link = hold;
- }
- }
- }
- }
- cout << brief->value << " ";
- brief = brief->link;
- }
- brief = head;
- }
- }
- }
- same = false;
- pos = 200;
- }
- }
- delete head,temp,hold,brief;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement