您的位置:首页 > 其它

1002. A+B for Polynomials (25)

2017-02-10 10:55 351 查看


题目大意:  输入两个多项式,计算多项式的和

#include<stdio.h>
//用数组表示多项式 数组下标为指数
void Build(int k, float array[])
{
for (int i = 0; i < 2000; i++)
array[i] = 0;
int ex; //指数
float coeff;//系数
for (int i = 1; i <= k; i++) {
scanf("%d %f", &ex, &coeff);
array[ex] = coeff;
}
}
int calclate(float a1[],float a2[],float result[])
{
int cnt = 0;
for (int i = 0; i < 2000; i++) {
result[i] = a1[i] + a2[i];
if (result[i] != 0)
cnt++;
}
return cnt;
}
int main()
{
float a1[2000], a2[2000];
int k1, k2;
scanf("%d", &k1);
Build(k1, a1);
scanf("%d", &k2);
Build(k2, a2);

float reault[2000];
int b;

b = calclate(a1, a2, reault);
printf("%d", b);
if (b != 0) {
for (int i = 2000 - 1; i >= 0; i--) {
if (reault[i] != 0) {
printf(" %d %.1f", i, reault[i]);
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: