讨论版
分享思路,答疑解惑,一起把题做明白。
Problem 3978
/ 帖子详情
错误50%,实在不明白,求大佬解惑
2
```
#include<stdio.h>
#include<stdlib.h>
int main()
{
typedef struct node
{
int date;
struct node *next;
}stu;
stu *head1,*head2,*head3,*s,*r,*k;
int i=0,m,n,q,p;
head1=(stu *)malloc(sizeof(stu));
head2=(stu *)malloc(sizeof(stu));
head3=(stu *)malloc(sizeof(stu));
scanf("%d",&m);
r=head1;
for(i=0;i<m;i++)
{
s=(stu *)malloc(sizeof(stu));
scanf("%d",&s->date);
r->next=s;
r=s;
}
r->next=NULL;
scanf("%d",&n);
r=head2;
for(i=0;i<n;i++)
{
s=(stu *)malloc(sizeof(stu));
scanf("%d",&s->date);
r->next=s;
r=s;
}
r->next=NULL;
r=head3;
for(i=0;i<n+m;i++)
{
s=(stu *)malloc(sizeof(stu));
s->date=0;
r->next=s;
r=s;
}
r->next=NULL;
s=head3->next;
r=head1->next;
k=head2->next;
while(r&&k)
{
q=r->date;
p=k->date;
if(q<=p)
{
s->date=r->date;
s=s->next;
r=r->next;
}
if(q>p)
{
s->date=k->date;
s=s->next;
k=k->next;
}
}
while(r)
{
s->date=r->date;
s=s->next;
r=r->next;
}
while(k)
{
s->date=k->date;
s=s->next;
k=k->next;
}
r=head3->next;
for(i=0;i<m+n;i++)
{
printf("%d ",r->date);
r=r->next;
}
}
````
```
#include<stdio.h>
#include<stdlib.h>
int main()
{
typedef struct node
{
int date;
struct node *next;
}stu;
stu *head1,*head2,*head3,*s,*r,*k;
int i=0,m,n,q,p;
head1=(stu *)malloc(sizeof(stu));
head2=(stu *)malloc(sizeof(stu));
head3=(stu *)malloc(sizeof(stu));
scanf("%d",&m);
r=head1;
for(i=0;i<m;i++)
{
s=(stu *)malloc(sizeof(stu));
scanf("%d",&s->date);
r->next=s;
r=s;
}
r->next=NULL;
scanf("%d",&n);
r=head2;
for(i=0;i<n;i++)
{
s=(stu *)malloc(sizeof(stu));
scanf("%d",&s->date);
r->next=s;
r=s;
}
r->next=NULL;
r=head3;
for(i=0;i<n+m;i++)
{
s=(stu *)malloc(sizeof(stu));
s->date=0;
r->next=s;
r=s;
}
r->next=NULL;
s=head3->next;
r=head1->next;
k=head2->next;
while(r&&k)
{
q=r->date;
p=k->date;
if(q<=p)
{
s->date=r->date;
s=s->next;
r=r->next;
}
if(q>p)
{
s->date=k->date;
s=s->next;
k=k->next;
}
}
while(r)
{
s->date=r->date;
s=s->next;
r=r->next;
}
while(k)
{
s->date=k->date;
s=s->next;
k=k->next;
}
r=head3->next;
for(i=0;i<m+n;i++)
{
printf("%d ",r->date);
r=r->next;
}
}
````
登录后即可参与回复 去登录