题目如下,代码亲测能过
#include<stdio.h>
#include<stdlib.h>
typedef struct list* List;
struct list{
int data;
List next;
};
int main()
{
int i,n,flag = 0;
List s1,s2,s3,t,S1,S2,S3;
S1 = (List)malloc(sizeof(struct list));
S2 = (List)malloc(sizeof(struct list));
S3 = (List)malloc(sizeof(struct list));
S3->next = NULL;
s1 = S1;
s2 = S2;
s3 = S3;
while(1){
scanf("%d",&n);
if(n == -1) break;
t = (List)malloc(sizeof(struct list));
t->data = n;
t->next = NULL;
s1->next = t;
s1 = s1->next;
}
while(1){
scanf("%d",&n);
if(n == -1) break;
t = (List)malloc(sizeof(struct list));
t->data = n;
t->next = NULL;
s2->next = t;
s2 = s2->next;
}
s1 = S1;
s2 = S2;
while(s1->next != NULL && s2->next != NULL){
if(s1->next->data == s2->next->data){
s3->next = s1->next;
s1 = s1->next;
s2 = s2->next;
s3 = s3->next;
}else if(s1->next->data > s2->next->data){
s2 = s2->next;
}else{
s1 = s1->next;
}
}
s3 = S3;
if(s3->next == NULL){
printf("NULL");
return 0;
}
while(s3->next != NULL){
if(!flag){
flag = 1;
printf("%d",s3->next->data);
}else{
printf(" %d",s3->next->data);
}
s3 = s3->next;
}
}