传送门
代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
int data;
struct node *next;
};
int main()
{
int n, i, cnt, m;
struct node *head, *tail, *p, *q;
head = (struct node *)malloc(sizeof(struct node));
head->next = NULL;
tail = head;
while(~scanf("%d", &n))
{
cnt = 0;
for(i=0; i<n; i++)
{
p = new node;
p->next = NULL;
scanf("%d", &p->data);
tail->next = p;
tail = p;
}
scanf("%d", &m);
printf("%d\n", n);
tail = head->next;
while(tail!=NULL)
{
if(tail->next==NULL)
printf("%d\n", tail->data);
else printf("%d ", tail->data);
tail= tail->next;
}
p = head;
q = head->next;
while(q!=NULL)
{
if(q->data==m)
{
p->next = q->next;
free(q);
cnt++;
}
else
p = p->next;
q = p->next;
}
printf("%d\n", n-cnt);
tail = head->next;
while(tail!=NULL)
{
if(tail->next==NULL)
printf("%d\n", tail->data);
else printf("%d ", tail->data);
tail = tail->next;
}
}
return 0;
}