#include <stdio.h>
#include <string.h>
#define MAXK 2000
float arr[MAXK];//结果存放在arr1中
int count;
int main()
{
int index;
float coeffi;
int n;
//freopen("/Users/pantingting/Documents/code/data/input", "r", stdin );
memset(arr, 0, sizeof(arr));
scanf("%d",&n);
for (int i=0; i<n; i++) {
scanf("%d%f",&index,&coeffi);
arr[index]=coeffi;
if (arr[index]!=0) {
count++;
}
}
scanf("%d",&n);
for (int i=0; i<n; i++) {
scanf("%d%f",&index,&coeffi);
int ini=arr[index];
arr[index]+=coeffi;
if (ini==0&&arr[index]!=0) {
count++;
}
if (ini!=0&&arr[index]==0) {
count--;
}
}
printf("%d",count);
for (int i=MAXK-1; i>=0; i--) {
if (arr[i]!=0) {
printf(" %d %.1f",i,arr[i]);
}
}
puts("");
return 0;
}
PAT 1002. A+B for Polynomials (25)
最新推荐文章于 2015-03-13 23:07:29 发布