https://pintia.cn/problem-sets/994805342720868352/problems/994805526272000000

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 N​1​​ a​N​1​​​​ N​2​​ a​N​2​​​​ ... N​K​​ a​N​K​​​​

where K is the number of nonzero terms in the polynomial, N​i​​ and a​N​i​​​​ (,) are the exponents and coefficients, respectively. It is given that 1,0.

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

代码:

#include <bits/stdc++.h>
using namespace std; double a[1010], b[1010];
int A, B;
double sum[1010]; int main() {
scanf("%d", &A);
for(int i = 1; i <= A; i ++) {
int x;
scanf("%d", &x);
scanf("%lf", &a[x]);
}
scanf("%d", &B);
for(int i = 1; i <= B; i ++) {
int y;
scanf("%d", &y);
scanf("%lf", &b[y]);
} int cnt = 0;
for(int i = 0; i <= 1000; i ++) {
if(a[i] && b[i])
sum[i] = a[i] + b[i];
else if(a[i])
sum[i] = a[i];
else if(b[i])
sum[i] = b[i];
}
for(int i = 0; i <= 1000; i ++) {
if(sum[i])
cnt ++;
}
printf("%d", cnt);
for(int i = 1000; i >= 0; i --) {
if(sum[i])
printf(" %d %.1lf", i, sum[i]);
}
printf("\n");
return 0;
}

  

PAT 甲级 1002 A+B for Polynomials的更多相关文章

  1. PAT 甲级 1002 A+B for Polynomials (25 分)

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

  2. PAT甲级 1002 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 ...

  3. PAT 甲级1002 A+B for Polynomials (25)

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

  4. PAT甲级——1002 A+B for Polynomials

    PATA1002 A+B for Polynomials This time, you are supposed to find A+B where A and B are two polynomia ...

  5. pat甲级1002

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

  6. 【PAT】1002. A+B for Polynomials (25)

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

  7. PAT——甲级1009:Product of Polynomials;乙级1041:考试座位号;乙级1004:成绩排名

    题目 1009 Product of Polynomials (25 point(s)) This time, you are supposed to find A×B where A and B a ...

  8. 甲级1002 A+B for Polynomials (25)

    题目描述: This time, you are supposed to find A+B where A and B are two polynomials. Input Each input fi ...

  9. PAT Advanced 1002 A+B for Polynomials (25 分)(隐藏条件,多项式的系数不能为0)

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

随机推荐

  1. mongodb导入全栈商城的goods和users数据

    > show dbsshow dbsadmin 0.000GBconfig 0.000GBlocal 0.000GB> use dumalluse dumallswitched to db ...

  2. Post 和 Get的区别?

    Post方法: 1. POST 请求的数据不会被缓存 2. Post请求的内容放置在HTML header中,用户是看不到这个过程的.所以是比较安全的 3. Post请求的数据大小没有限制 Get方法 ...

  3. 终于搞定了cxgrid的多行表头(转终于搞定了cxgrid的多行表头 )

    终于搞定了cxgrid的多行表头 转自:http://mycreature.blog.163.com/blog/static/556317200772524226400/     这一周都在处理dbg ...

  4. Django自带后台使用配置

    参考官网地址:https://docs.djangoproject.com/en/1.11/ref/contrib/admin/ ,本文章值是介绍简单配置,如果需要详细内容可以查阅官方文档 自动管理界 ...

  5. js bom和dom

    一, 前言 到目前为止,我们已经学过了JavaScript的一些简单的语法.但是这些简单的语法,并没有和浏览器有任何交互. 也就是我们还不能制作一些我们经常看到的网页的一些交互,我们需要继续学习BOM ...

  6. Leecode刷题之旅-C语言/python-70爬楼梯

    /* * @lc app=leetcode.cn id=70 lang=c * * [70] 爬楼梯 * * https://leetcode-cn.com/problems/climbing-sta ...

  7. mysql 5.8 查询最新一条数据

    SELECT * FROM ( ,) FROM (SELECT * FROM or_task_node ORDER BY created_date DESC) temp ) AS vars ) t g ...

  8. (数据科学学习手札03)Python与R在随机数生成上的异同

    随机数的使用是很多算法的关键步骤,例如蒙特卡洛法.遗传算法中的轮盘赌法的过程,因此对于任意一种语言,掌握其各类型随机数生成的方法至关重要,Python与R在随机数底层生成上都依靠梅森旋转(twiste ...

  9. python2.7练习小例子(二十三)

        23):题目:求1+2!+3!+...+20!的和.     程序分析:此程序只是把累加变成了累乘. #!/usr/bin/python # -*- coding: UTF-8 -*- n = ...

  10. Oracle错误记录

    1 SQLPlus无法登陆oracle,PLSql可以登陆,报错ORA-12560 环境变量 右击计算机属性-->高级系统设置-->高级-->环境变量-->系统变量--> ...