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. 爬虫——json模块与jsonpath模块

    JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,它使得人们很容易的进行阅读和编写.同时也方便了机器进行解析和生成.适用于进行数据交互的场景,比如网站前台与后 ...

  2. Java语言利用Collections.sort对Map,List排序

    1.main方法包含TreeMap排序1,TreeMap排序2,HashMap排序,List<Integer>排序,List<Bean>排序,List<Map>排序 ...

  3. Asp.Net Core 使用Docker进行容器化部署(一)

    前几篇文章介绍了Liunx下的环境搭建,今天来分享一下.Net Core在Liunx上的部署. 我采用的方案是使用Dokcer作为运行虚拟机,Nginx作为Http服务器来进行反向代理,你可以理解为D ...

  4. 查询表名里含有Bill的表有哪些

    Select Name from Master.dbo.sysobjects where xtype='u' and Name like '%Bill%' order by name

  5. 关于Linux中mysql中文乱码

    1.SHOW VARIABLES LIKE 'character_set_%';查看编码集 2.编辑/etc/my.cnf文件 加入这个设置 default-character-set=utf8 (这 ...

  6. Java应用:经纬度匹配(geohash加密)

    本文采用http://gc.ditu.aliyun.com地址进行经纬度匹配,无数量限制 如果给定经纬度进行geohash加密操作,先解密得到相应gps坐标,具体程序如下所示: import java ...

  7. 按升序打印X,Y,Z的整数值

    #include <stdio.h> #define TRUE 1 #define FALSE 0 int main() { int x,y,z; printf("x: &quo ...

  8. Linux mysql启动与关闭

    service mysql stop service mysqld start

  9. 《UML大战需求分析》阅读笔记1

    通过阅读本书的序和第一章,让我对于UML的理解更加深刻了,并且懂了怎样把你UML学的更好. 作者先让我们明白什么是UML,大概知道了UML各个图的形态和各种用途,然后再详细的介绍各个图怎样使用. UM ...

  10. 初步学习pg_control文件之十三

    接前文,初步学习pg_control文件之十二 看这个: * backupStartPoint is the redo pointer of the backup start checkpoint, ...