首页 > 代码库 > PAT 1002. A+B for Polynomials
PAT 1002. A+B for Polynomials
#include<stdio.h> #include<string.h> double coefficient[1010]; int k1, k2,k3=0; int nk; int max_exponent1, max_exponent2; int min_exponent1, min_exponent2; int main(){ memset(coefficient, 0, sizeof coefficient); scanf("%d", &k1); for (int i = 0; i < k1; i++){ scanf("%d", &nk); scanf("%lf", &coefficient[nk]); if (i == 0)max_exponent1 = nk; if (i == k1 - 1)min_exponent1 = nk; } scanf("%d", &k2); double coeff; for (int i = 0; i < k2; i++){ scanf("%d %lf", &nk, &coeff); coefficient[nk] += coeff; if (i == 0)max_exponent2 = nk; if (i == k2 - 1)min_exponent2 = nk; } int min_exponent = min_exponent1<min_exponent2 ? min_exponent1 : min_exponent2; int max_exponent = max_exponent1 > max_exponent2 ? max_exponent1 : max_exponent2; for (int i = max_exponent; i >= min_exponent; i--){ if (coefficient[i] == 0)continue; k3++; } printf("%d", k3); for (int i = max_exponent; i >= min_exponent; i--){ if (coefficient[i] == 0){ continue; } printf(" %d %.1lf", i, coefficient[i]); } return 0; }
PAT 1002. A+B for Polynomials
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。