http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2122
#include <stdio.h>
#include <malloc.h>
typedef struct node
{
int data;
struct node* next;
}Linklist;
int main()
{
int n,i,flag,count;
Linklist *h,*p,*pre,*q;
scanf("%d",&n);
h=(Linklist*)malloc(sizeof(Linklist));
h->next=NULL;
for(i=1;i<=n;i++)
{
p=(Linklist*)malloc(sizeof(Linklist));
scanf("%d",&p->data);
p->next=h->next;
h->next=p;
}
printf("%d\n",n);
for(i=1;i<=n;i++)
{
if(p->next!=NULL)
printf("%d ",p->data);
else
printf("%d\n",p->data);
p=p->next;
}
pre=h;
p=h->next;
while(p)
{
q=h->next;
flag=0;
while(q!=p)
{
if(q->data==p->data)
{
flag=1;
break;
}
q=q->next;
}
if(flag==1)
{
pre->next=p->next;
free(p);
p=pre->next;
continue;
}
pre=p;
p=p->next;
}
p=h->next;
count=0;
while(p)
{
count++;
p=p->next;
}
printf("%d\n",count);
p=h->next;
while(p)
{
if(p->next!=NULL)
printf("%d ",p->data);
else
printf("%d\n",p->data);
p=p->next;
}
return 0;
}
/**************************************
Problem id : SDUT OJ 2122
User name : 2333
Result : Accepted
Take Memory : 276K
Take Time : 0MS
Submit Time : 2016-07-20 14:34:46
**************************************/