#include <stdio.h>
#include <stdlib.h>
typedef struct Exp
{
int xishu;
int cishu;
}Exp;
int main()
{
int m,n,i,j,k;
Exp *a,*b,*c;
while(scanf("%d",&m)!=EOF)
{
a=(Exp *)malloc(m*sizeof(Exp));
for(i=0;i<m;i++)
scanf("%d%d",&a[i].xishu,&a[i].cishu);
scanf("%d",&n);
b=(Exp *)malloc(n*sizeof(Exp));
for(i=0;i<n;i++)
scanf("%d%d",&b[i].xishu,&b[i].cishu);
c=(Exp *)malloc((m+n)*sizeof(Exp));
for(i=0,j=0,k=0;i<m&&j<n;)
{
if(a[i].cishu>b[j].cishu)
c[k++]=a[i++];
else if(a[i].cishu<b[j].cishu)
c[k++]=b[j++];
else
{
if((a[i].xishu+b[j].xishu)!=0)
{
c[k].cishu=a[i].cishu;
c[k++].xishu=a[i++].xishu+b[j++].xishu;
}
else
{
i++;
j++;
}
}
}
if(i==m&&j!=n)
while(j!=n) c[k++]=b[j++];
else if(i!=m&&j==n)
while(i!=m) c[k++]=a[i++];
if(k!=0)
{
for(i=0;i<k-1;i++)
printf("%d %d ",c[i].xishu,c[i].cishu);
printf("%d %d",c[i].xishu,c[i].cishu);
}
printf("\n");
free(a);
free(b);
free(c);
}
return 0;
}
此代码有什么问题?测试N遍都没有问题!为什么就是不能AC!!!