#include <stdio.h>
#include <ctype.h>
#include <string.h>
 
typedef struct _node {
  int key;
  struct _node *next;
  struct _node *prev;
} NODE, *PNODE;
 
PNODE root;
 
void init(void) {
  root = malloc(sizeof(NODE));
  root->next = root;
  root->prev = root;
}
 
void insert(key) {
  PNODE t = malloc(sizeof(NODE));
  t->key = key;
  t->next = root->next;
  t->prev = root;
  root->next->prev = t;
  root->next = t;
}
 
void deleteNode(PNODE node) {
  if (node == root) {
    return;
  }
  node->next->prev = node->prev;
  node->prev->next = node->next;
  free(node);
}
 
void delete(key) {
  PNODE cur = root->next;
  while (cur != root) {
    if (cur->key == key) {
      deleteNode(cur);
      return;
    }
    cur = cur->next;
  }
}
 
void deleteFirst(void) {
  deleteNode(root->next);
}
 
void deleteLast(void) {
  deleteNode(root->prev);
}
 
void printNodes(void) {
  PNODE cur = root->next;
  while (1) {
    printf("%d", cur->key);
    cur = cur->next;
    if (cur != root) {
      putchar(' ');
    } else {
      break;
    }
  }
  putchar('\n');
}
 
void release(void) {
  PNODE tmp, cur = root->next;
  while (cur != root) {
    tmp = cur;
    cur = cur->next;
    deleteNode(tmp);
  }
  free(root);
} 
 
int main(void) {
  char cmd[100];
  int n, i, f;
  int key;
 
  init(); 
 
  scanf("%d", &n);
 
  f = 0;
  while (scanf("%s", cmd) > 0) {
    if (cmd[0] == 'i') {
      f = 1;
    } else if (cmd[0] == 'd') {
      switch (cmd[6]) {
      case '\0':
    f = 2;
    break;
      case 'F':
    deleteFirst();
    break;
      case 'L':
    deleteLast();
    break;
      }
    } else {
      key = atoi(cmd);
      if (f == 1) {
    insert(key);
      } else if (f == 2) {
    delete(key);
      }
    }
  }
 
  printNodes();
 
  release();
 
  return 0;
}
Compile Error Logs:
You are not authorized to see the message.

???????????????
Judge: 10/10 	C 	CPU: 00.27 sec 	Memory: 31852 KB 	Length: 1732 B 	2016-07-11 23:25 	2016-07-11 23:25
???????????±?????????????????????
Case # 	Verdict 	CPU Time 	Memory 	In 	Out 	Case Name
Case #1: 	: Accepted 	00.00 sec 	600 KB 	88 B 	2 B 	01.in
Case #2: 	: Accepted 	00.00 sec 	600 KB 	203 B 	10 B 	02.in
Case #3: 	: Accepted 	00.00 sec 	600 KB 	375 B 	10 B 	03.in
Case #4: 	: Accepted 	00.00 sec 	600 KB 	105 B 	23 B 	04.in
Case #5: 	: Accepted 	00.00 sec 	600 KB 	643 B 	58 B 	05.in
Case #6: 	: Accepted 	00.00 sec 	600 KB 	52 B 	2 B 	06.in
Case #7: 	: Accepted 	00.00 sec 	596 KB 	1058 B 	110 B 	07.in
Case #8: 	: Accepted 	00.00 sec 	596 KB 	1031 B 	116 B 	08.in
Case #9: 	: Accepted 	00.21 sec 	604 KB 	22392494 B 	5 B 	09.in
Case #10: 	: Accepted 	00.27 sec 	31852 KB 	25527813 B 	1288799 B 	10.in
< prev | 	1 	/ 	10 	| next > 	  		 : Accepted        00.00 sec        600 KB
 
Judge Input #1 ( in1.txt | 88 B) 		Judge Output #1 ( out1.txt | 2 B)

9
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
deleteFirst
deleteLast

		

1

Comments
 
 ??\????????§??????
 
Categories
 
 
Free Tags
 
 