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; }
相关文章推荐
- PAT 1002. A+B for Polynomials (25)
- PAT甲级 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- PAT甲级1002. A+B for Polynomials (25)
- 【PAT】1002. A+B for Polynomials(25)
- PAT-A-1002. A+B for Polynomials (25)
- PAT - 甲级 - 1002. A+B for Polynomials (25)
- PAT甲级-1002. A+B for Polynomials (25)多项式
- 1002. A+B for Polynomials (25)
- PAT TEST甲级1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- PAT甲 1002. A+B for Polynomials (25)
- PAT (Advanced Level) 1002. A+B for Polynomials (25) 合并同类项
- 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)