#include<cstdio>
#include<cstring>
int main()
{
int n,m;
scanf("%d",&n);
int ni;
double poly;
double term[1050]={0};
int flag[1050]={0};
int sum=0;
for(int i=0;i<n;i++ )
{
scanf("%d %lf",&ni,&poly);
term[ni] = poly;
flag[ni]=1;
sum++;
}
scanf("%d",&m);
for(int i=0;i<m;i++)
{
scanf("%d %lf",&ni,&poly);
term[ni] += poly;
if(term[ni]==0) {flag[ni] =0;sum--;continue;}
if(flag[ni]==1) continue;
flag[ni]=1;sum++;
}
if(sum==0){ printf("0"); return 0;}
printf("%d ",sum);
for(int i = 1001;i>=0;i--)
{
if(flag[i]==1)
{
printf("%d ",i);
printf("%.1f",term[i]);
sum--;
if(sum!=0) printf(" ");
}
}
}
这里面犯的几个错误1,是要求系数非0;
1.如果k=0;则直接输入0 就结束,后面不能在跟空格