一、题目

This time, you are supposed to find A+B where A and B are two polynomials.

Input Specification:
Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 … NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, …, K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10,0 <= NK < … < N2< N1 <=1000.

Output Specification:
For each test case you should output the sum of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate to 1 decimal place.

Sample Input

2 1 2.4 0 3.2
2 2 1.5 1 0.5

Sample Output

3 2 1.5 1 2.9 0 3.2

二、题意

单词 意思
polynomial 多项式
exponent 指数
coefficient 系数
respectively 分别地,各自地
1 decimal place 小数点第一位

给出两行,每行均为一个多项式。K为多项式中非零项的个数,Ni为多项式的指数,aNi为多项式的系数。求两个多项式的和,并以输入格式输出结果。非零项项数,以及高次到低次输出非零项的指数和系数

三、思路

定义一个数组,其中p[n]表示指数n的项的系数,初值为0。

四、注意

1、注意输出格式,从高次到低次
2、精确到一位小数
3、count计数非零项项数时,不要选择在读入时计数,存在正负相抵问题

五、代码

#include <cstdio>
using namespace std;
int main() {int m, n, e;float c;float a[1005] = { 0 };scanf_s("%d", &m);for (int i = 1; i <= m; i++) {scanf_s("%d %f", &e, &c);a[e] += c;}scanf_s("%d", &n);for (int i = 1; i <= n; i++) {scanf_s("%d %f", &e, &c);a[e] += c;}int count = 0;for (int i = 0; i <= 1000; i++) {if (a[i] != 0) count++;}printf("%d", count);for (int i = 1000; i >=0; i--) {//输出格式应该从高次到低次if (a[i] != 0.0)//判断非零项printf(" %d %.1f", i, a[i]);//%.1f精确到小数点后一位}return 0;
}

PAT A1002 A+B for Polynomials (25 分)相关推荐

  1. PAT甲级1009 Product of Polynomials (25分)

    PAT甲级1009 Product of Polynomials (25分) 题目: 题目分析:和之前有一道多项式相加很像,注意点是不仅仅数组系数会变,还可能会出现之前没有的指数,因此要开2001大小 ...

  2. PAT甲级 -- 1009 Product of Polynomials (25 分)

    This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...

  3. PAT A1002 A+B for Polynomials(25)

    AC代码 转载自https://www.cnblogs.com/zjutJY/p/9413766.html #include <stdio.h> #include<string.h& ...

  4. 【PAT】B1070 结绳(25 分)

    此题太给其他25分的题丢人了,只值15分 注意要求最终结果最长,而且向下取整 #include<stdio.h> #include<algorithm> using names ...

  5. 【PAT甲】1051 Pop Sequence (25分)判断出栈顺序的合法性

    problem 1051 Pop Sequence (25分) Given a stack which can keep M numbers at most. Push N numbers in th ...

  6. 【PAT乙】1065 单身狗 (25分)

    1065 单身狗 (25分) "单身狗"是中文对于单身人士的一种爱称.本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱. 输入格式: 输入第一行给出一个正整数 N(≤ ...

  7. 【PAT乙】1030 完美数列 (25分) 枚举

    1030 完美数列 (25分) 给定一个正整数数列,和正整数 p,设这个数列中的最大值是 M,最小值是 m,如果 M≤mp,则称这个数列是完美数列. 现在给定参数 p 和一些正整数,请你从中选择尽可能 ...

  8. 【PAT】1030 完美数列 (25 分)

    1030 完美数列 (25 分) 给定一个正整数数列,和正整数 p,设这个数列中的最大值是 M,最小值是 m,如果 M≤mp,则称这个数列是完美数列. 现在给定参数 p 和一些正整数,请你从中选择尽可 ...

  9. PAT甲级-1021 Deepest Root(25分)

    题目:1021 Deepest Root(25分) 分析:找出以某个节点为根时,最深的根,这题可能会超时要用vector来表示二维数组 疑问:代码一是第二次写的超时了,代码二是第一次写的AC了,找不出 ...

  10. PAT甲级--1007 Maximum Subsequence Sum (25 分)

    题目详情 - 1007 Maximum Subsequence Sum (25 分) (pintia.cn) Given a sequence of K integers { N1​, N2​, .. ...

最新文章

  1. java vuser脚本_loadrunner12中JavaVuser脚本的编写
  2. 量子信息技术研究现状与未来
  3. Android服务之AIDL
  4. 产品管理必修课:发布新版本不等于改进产品
  5. Java(Android)线程池
  6. 深入研究 Mini ASP.NET Core,看看 ASP.NET Core 内部到底是如何运行的
  7. 我如何想成为Java
  8. 最大化BEA WebLogic Cluster的性能、可用性和安全
  9. python ctypes
  10. C语言的soap报文处理转义字符,webservice传递特殊字符时的解决办法
  11. 谁说互联网行业发展走到了尽头?
  12. Vue报错Module build failed Error Node Sass version 6.0.1 is incompatible with ^4.0.0.解决方案
  13. VirtualBox没有64位选项,无法安装64位的解决方法(zhuan)
  14. UVA12169 Disgruntled Judge
  15. LINUX Centos7利用七牛空间做定时备份 qshell定时备份,定时上传到七牛空间
  16. python 100 days github_GitHub - Andyhe2019/Python-100-Days: Python - 100天从新手到大师
  17. 前端实现鼠标拖拽功能
  18. 【SpringBoot实战】分布式定时任务锁Shedlock
  19. 转:著名的100个管理定律点评10
  20. 【活动】微软社区秋日巡讲——Windows Phone 应用开发训练营

热门文章

  1. 医学CT图像三维重建代码
  2. SQL Server表空间碎片化回收
  3. 第十届山东理工大学ACM网络编程擂台赛 重现
  4. PyTorch学习(九)--用CNN模型识别手写数字数据集MNIST
  5. python解二元方程组_Python 解线性方程组
  6. node.js学习笔记(8)--multer模块文件上传
  7. egret引擎生命周期相关
  8. go语言:sync.Once的用法(转)
  9. htmL中怎么使图片轮播,网页设计中怎么让图片轮播
  10. 单播、广播和多播IP地址