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

Input

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

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
 #include<cstdio>
#include<iostream>
using namespace std;
int main(){
int K, n, count = ;
double poly1[] = {}, poly2[] = {}, a;
scanf("%d", &K);
for(int i = ; i < K; i++){
scanf("%d%lf", &n, &a);
poly1[n] = a;
}
scanf("%d", &K);
for(int i = ; i < K; i++){
scanf("%d%lf", &n, &a);
poly2[n] = a;
}
for(int i = ; i >= ; i--){
poly1[i] = poly1[i] + poly2[i];
if(poly1[i] != )
count++;
}
printf("%d", count);
for(int i = ; i >= ; i--){
if(poly1[i] != )
printf(" %d %.1lf", i, poly1[i]);
}
cin >> K;
return ; }

总结:

1、多项式加法,在项数不多的情况下直接开数组。

2、注意不用输出系数为0的项

A1002. A+B for Polynomials的更多相关文章

  1. A1002 A+B for Polynomials (25)(25 分)

    1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...

  2. PAT甲级——A1002 A+B for Polynomials

    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

    仅有两个要注意的点: 如果系数为0,则不输出,所以输入结束以后要先遍历确定系数不为零的项的个数 题目最后一句,精确到小数点后一位,如果这里忽略了,会导致样例1,3,4,5都不能通过

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

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

  5. PAT/简单模拟习题集(二)

    B1018. 锤子剪刀布 (20) Discription: 大家应该都会玩"锤子剪刀布"的游戏:两人同时给出手势,胜负规则如图所示: 现给出两人的交锋记录,请统计双方的胜.平.负 ...

  6. PAT题目AC汇总(待补全)

    题目AC汇总 甲级AC PAT A1001 A+B Format (20 分) PAT A1002 A+B for Polynomials(25) PAT A1005 Spell It Right ( ...

  7. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

  8. 1002 A+B for Polynomials (25 分)

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

  9. 1002. A+B for Polynomials (25)

    题目链接:https://www.patest.cn/contests/pat-a-practise/1002 原题如下: This time, you are supposed to find A+ ...

随机推荐

  1. SpringBoot 中 JPA 的使用

    详细连接 简书https://www.jianshu.com/p/c14640b63653 新建项目,增加依赖 在 Intellij IDEA 里面新建一个空的 SpringBoot 项目.具体步骤参 ...

  2. Android——MaterialDesign之四 FloatingActionButton、Snackbar、CoordinaterLayout

    FloatingActionButton 悬浮按钮,默认colorAccent来作为按钮的颜色 <android.support.design.widget.FloatingActionButt ...

  3. CentOS7 网络NAT模式

    问题:安装完毕ping命令不能用,然后改为桥接模式,ping可以用. 先了解桥接,NAT 的含义. 桥接:在bridged模式下,VMWare虚拟出来的操作系统就像是局域网中的一台独立的主机,它可以访 ...

  4. MyBatis基础:MyBatis数据基本操作(2)

    1. MyBatis映射器 2. MyBatis数据基本操作 示例项目结构: <project xmlns="http://maven.apache.org/POM/4.0.0&quo ...

  5. 去掉AMD锐龙和Intel Kaby Lake的不支持的硬件的提示

    Windows 7和Windows 8.1都不支持AMD Ryzen 锐龙系列和Intel最新的Kaby Lake系列,Windows Update 更新之后总是会提示“不支持的硬件(Unsuppor ...

  6. Linux命令替换字符串

    :%s/str1/str2/ 用str2替换str1

  7. Linux命令归纳

    Linux基本命令 Linux Xshell远程连接 ssh 用户名@id地址 例如: ssh root@192.168.11.53 增加类指令 创建文件夹 mkdir 文件名 mkdir -p 路径 ...

  8. 【XSY2528】道路建设 LCT 可持久化线段树

    题目描述 给你一个\(n\)个点\(m\)条边图,\(q\)个询问,每次问你边权在\([l,r]\)之间的边组成的最小生成树(森林)的边权和.强制在线. \(n,m,q\leq 100000\) 题解 ...

  9. Java归并排序的递归与非递归实现

    该命题已有无数解释,备份修改后的代码 平均时间复杂度: O(NLogN)  以2为底 最好情况时间复杂度: O(NLogN) 最差情况时间复杂度: O(NLogN) 所需要额外空间: 递归:O(N + ...

  10. python学习日记(2/3区别,环境,变量,数据类型以及简单习题)

    Python2 与 python3 的区别: python2源码不标准,混乱,重复代码太多 python3统一标准,去除重复代码 python2的默认编码方式是ASCII码,不能识别中文.解决方法:在 ...