#include <stdio.h>
#include <stdlib.h>
struct ListNode
{
int data;
struct ListNode *next;
};
struct ListNode *readlist();
struct ListNode *deletem(struct ListNode *L, int m);
void printlist(struct ListNode *L)
{
struct ListNode *p = L;
while (p)
{
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}
int main()
{
int m;
struct ListNode *L = readlist();
scanf("%d", &m);
L = deletem(L, m);
printlist(L);
return 0;
}
struct ListNode *readlist()
{
struct ListNode *head, *tail, *p;
head = tail = NULL;
while (1)
{
p = (struct ListNode *)malloc(sizeof(struct ListNode));
scanf("%d", &(p->data));
if (p->data < 0)
break;
p->next = NULL;
if (head == NULL)
head = p;
else
tail->next = p;
tail = p;
}
return head;
}
struct ListNode *deletem(struct ListNode *L, int m)
{
struct ListNode *p, *head;
while (1)
{
if (L == NULL || L->data != m)
{
head = L;
break;
}
else if (L->data == m)
L = L->next;
}
if (head == NULL || head->next == NULL)
return head;
while (1)
{
if (L == NULL)
break;
p = L;
L = L->next;
if (L == NULL)
break;
if (L->data == m)
{
while (1)
{
if (L == NULL || L->data != m)
break;
L = L->next;
}
p->next = L;
}
}
return head;
}