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. Oracle调优总结

    Oracle调优总结(经典实践 重要) https://blog.csdn.net/dtjiawenwang88/article/details/74892245 https://www.cnblog ...

  2. Excel文件读取的两种方式

    1.Pandas库的读取操作 from pandas import read_excel dr=read_excel(filename,header) dr#dataframe数据 dw=DataFr ...

  3. linux 下crontab -e 命令插入及保存

    由于功能需要,用到linux定时任务. 一般我们都是crontab -e 进去写好定时任务,直接保存退出就可以了,如果是第一次创建定时任务, 系统会选择默认编辑器,就不好保存文件. 在网上参考了一篇文 ...

  4. 莫烦scikit-learn学习自修第一天【scikit-learn安装】

    1. 机器学习的分类 (1)有监督学习(包括分类和回归) (2)无监督学习(包括聚类) (3)强化学习 2. 安装 (1)安装python (2)安装numpy >=1.6.1 (3)安装sci ...

  5. Java HashMap的put操作(Java1.8)

    https://www.cnblogs.com/JzedyBlogs/p/10208295.html 写得非常好: 这个是Java1.8 ------------------------------- ...

  6. FormDestroy 和 FormClose 有什么区别和联系?

    1.窗口的所有资源真正释放时调用 FormDestroy.当你关闭窗口时,VCL会调用FormClose,如果你在FormClose里写Action = caFree,那么VCL会继续调用FormDe ...

  7. vscode運行vue和html

    html 选中html文件,右键选择view in broswer.

  8. vue表單

    使用v-model進行表單雙向數據綁定. 可以根據控件決定數據的類型,可以綁定input.單選.複選.下拉框等 可以使用number和trim等修飾符.

  9. SpringBoot之处理JSON数据举例

    SpringBoot使用@RequestBody注解会自动将请求body中的json数据绑定到参数上.使用@ResponseBody注解,在返回参数时自动将对象转换为JSON格式返回. 举例代码: c ...

  10. Linq:使用Take和Skip实现分页

    Skip,Take: list = list.Skip(pageNum * pageSize).Take(pageSize).ToList(); pageSize :表示一页多少条. pageNum: ...