1002|1002 A+B for Polynomials (25)(25 分)

【1002|1002 A+B for Polynomials (25)(25 分)】建立数组,数组下标作为指数

#include using namespace std; const int maxn = 1e3 + 10; double a[maxn], b[maxn]; int k; void read(double a[]) { scanf("%d", &k); for (int i = 0; i < k; i++) { int exp; double coef; scanf("%d%lf", &exp, &coef); a[exp] = coef; } } int main() { read(a); read(b); int cnt = 0; for (int i = 0; i < maxn; i++) { a[i] += b[i]; if (a[i])cnt++; } printf("%d", cnt); for (int i = maxn; i >= 0; i--) { if (a[i])printf(" %d %.1f", i, a[i]); } return 0; }

    推荐阅读