POJ-2259

#include <stdio.h>
#include <string.h>
#include <malloc.h>

typedef struct node *node_pointer;
struct node {
       int value;
       node_pointer link;
       };

node_pointer top, rear;
node_pointer team[1101] = {0};

short int num[1000100];


void inqueues(int n)
{
     node_pointer temp;
     temp = malloc(sizeof(struct node));
     temp->value = n;
     if (!top) {
        temp->link = NULL;
        top = rear = temp;
     }
     else {
          if (team[num[n]]) {
             temp->link = team[num[n]]->link;
             team[num[n]]->link = temp;
          }
          else {
               rear->link = temp;
			   temp->link = NULL;
          }
     }
     team[num[n]] = temp;
}

void outqueues(void)
{
     node_pointer temp;
     temp = top;
     top = top->link;
     printf("%d\n", temp->value);
     free(temp);
}

int main()
{
    long t, elements, n, i = 0; 
    node_pointer temp;   
    char command[10];
    scanf("%d", &t);
    while (t) {
		  top = rear = NULL;
          while (t) {
                scanf("%d", &elements);
                while (elements--) {
                      scanf("%d", &n);
                      num[n] = t; 
                }
                t--;
          }
          printf("Scenario #%d\n", ++i);
          while (scanf("%s", command), command[0] != 'S') {
                if (command[0]== 'E') {
                   scanf("%d", &n);
                   inqueues(n);
                }
                else
                    outqueues();
          }
          scanf("%d", &t);
          if (t)
             printf("\n");
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章