首页 > 代码库 > 1002. A+B for Polynomials (25)

1002. A+B for Polynomials (25)

题目: 1002. A+B for Polynomials (25)

#include<stdio.h>#define N 1000int main(){    double poly[N+1]={0};    int n,m,i;    int exp;    double coef;    scanf("%d",&n);    m=n;    for(i=0;i<n;i++)    {        scanf(" %d %lf",&exp,&coef);        poly[exp]=coef;    }    scanf("%d",&n);    m+=n;    for(i=0;i<n;i++)    {        scanf(" %d %lf",&exp,&coef);        if(poly[exp])m--;        poly[exp]+=coef;        if(poly[exp]==0)m--;    }    printf("%d",m);    for(i=N;i>=0;i--)    {        if(poly[i])printf(" %d %.1lf",i,poly[i]);    }}

 

1002. A+B for Polynomials (25)