A+B算法,来拿分了,该怎么处理

A+B算法,来拿分了
题目连接,http://pat.zju.edu.cn/contests/pat-a-practise/1002
通过部分数据,有部分不通过,是那种数据的错误呢,我的代码

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef struct 
{
int a;
double b;
}Node;
Node ary[1003];
int main()
{
int k,i,t,max;
int num;
double temp;
for(i = 0;i < 1003;i++)
{
ary[i].a = -1;ary[i].b = 0;
}
freopen("in.txt","r",stdin);
scanf("%d",&k);
t = 0;max = 0;
for(i = 0;i < k;i++)
{
scanf("%d",&num);
if(num > max) max = num;
ary[num].a = num;
scanf("%lf",&ary[num].b);
t++;
}
scanf("%d",&k);
for(i = 0;i < k;i++)
{
scanf("%d",&num);
if(num > max) max = num;
scanf("%lf",&temp);
if(ary[num].a != -1)
{
ary[num].b += temp;
continue;
}
else
{
ary[num].a = num;
ary[num].b = temp;
}
t++;
}
printf("%d",t);
for(i = max+1;i >= 0;i--) 
{
if(ary[i].a != -1)
printf(" %d %.1lf",i,ary[i].b);
}
printf("\n");
}

------解决方案--------------------
如果系数是0,不要输出。
#include<stdio.h>  
typedef struct poly  
{  
    int exp;  
    double coef;  
}poly;  
int main()  
{  
    poly x[30],y[30],z[30];  
    int k1,k2,i,j,k;  
    scanf("%d",&k1);  
    for(i=0;i<k1;i++)  
        scanf("%d %lf",&x[i].exp,&x[i].coef);  
    scanf("%d",&k2);  
    for(j=0;j<k2;j++)  
        scanf("%d %lf",&y[j].exp,&y[j].coef);  
    i=0;  
    j=0;  
    k=0;  
    while(i<k1&&j<k2)  
    {  
        if(x[i].exp==y[j].exp&&x[i].coef+y[j].coef!=0)  
        {  
            z[k].exp=x[i].exp;  
            z[k].coef=x[i].coef+y[j].coef;  
            k++;  
            i++;  
            j++;  
        }  
        else  
            if(x[i].exp==y[j].exp)  
            {