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. Linux mongodb安装、启动、运行

    1.下载     wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.4.tgz     2.安装     tar -zxvf  ...

  2. Nginx从搭建到配置支持HTTPS

    原文地址:https://www.xingkongbj.com/blog/nginx/nginx.html 安装 基础包 ububtu apt-get install build-essential ...

  3. php第二节(变量、常量)

    <?php /** * 类型转换 * 自动转换 数据在运算过程中自动转换 * 空字符串 false * "0" false * null false * 0 false * ...

  4. jzoj5196. 【NOIP2017提高组模拟7.3】B (数论,巧妙的暴力)

    Description

  5. 浅谈linux系统中pdf文件的默认打开方式

    atril.gimp和evince,三者均可以打开application/pdf格式文件.gimp为一款图像处理软件:atril为mate环境下常用的文档查看器:evince为gnome环境下常用的文 ...

  6. shell 输出带颜色字体

    输出特效格式控制:\033[0m  关闭所有属性  \033[1m   设置高亮度  \03[4m   下划线  \033[5m   闪烁  \033[7m   反显  \033[8m   消隐  \ ...

  7. web3.js_1.x.x--API(一)event/Constant/deploy/options

    /* 事件是使用EVM日志内置功能的方便工具,在DAPP的接口中,它可以反过来调用Javascript的监听事件的回调. 事件在合约中可被继承.当被调用时,会触发参数存储到交易的日志中(一种区块链上的 ...

  8. YII2.O学习三 前后台用户数据表分离

    之前我们完成了Advanced 模板安装,也完成了安装adminlte 后台模板,这一步是针对前端和后台用户使用不同的数据库表来管理,做到前后台用户分离的效果: 复制一张user数据表并重命名为adm ...

  9. 使用MapReduce读取HBase数据存储到MySQL

    Mapper读取HBase数据 package MapReduce; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hba ...

  10. Matplotlib 子图的创建

    在matplotlib中,整个图像为一个Figure对象 在Figure对象中可以包含一个或者多个Axes对象  每个Axes对象相当于一个子图了 每个Axes(ax)对象都是一个拥有自己坐标系统的绘 ...