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

使用map进行映射即可,但需注意输出格式
 #include <iostream>
//#include <vector>
#include <map>
#include <stack>
using namespace std; int main()
{
map<double, double,greater<double>>data;//从大到小排序
for (int i = ; i < ; ++i)//输入两组数据
{
int k;
cin >> k;
for (int j = ; j < k; ++j)//接受每组数据
{
double a, b;
cin >> a >> b;
data[a] += b;
if (data[a] == )//系数为0则删除
data.erase(a);
}
}
cout << data.size();
for (auto ptr = data.begin(); ptr != data.end(); ++ptr)
{
cout << " " << ptr->first << " ";
printf("%.1f", ptr->second);
}
return ;
}
 

最新文章

  1. install usb serial
  2. POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)
  3. cocos2dx Android 环境搭建 以及 ndk调试
  4. php开启curl和openssl
  5. Javascript获取某个月的天数-简单方法 .(转别人的)
  6. AFNetworking2.0后 进行Post请求
  7. DocFX生成PDF文档
  8. Talk 3: Rob Pike on Upspin (Gopherfest 2017)
  9. java.lang.Boolean 类源码解析
  10. DS哈希查找--线性探测再散列
  11. 【转】每天一个linux命令(49):at命令
  12. 【转】SSL协议详解
  13. 尺取法拓展——POJ3320
  14. 浅谈splay
  15. CryptoZombies学习笔记——Lesson4
  16. Mybatis 一个搜索框对多个字段进行模糊查询
  17. chrome浏览器自动填充失效问题
  18. windows安装redis并设置别名
  19. 飞镖(bzoj 2335)
  20. 第七篇 elasticsearch 链接mysql不会更新

热门文章

  1. [JZOJ3235] 数字八
  2. 网络攻击之代理IP
  3. thinkphp扩展配置
  4. Mysq 列中存储json格式根据key取value
  5. day23_4_hashlib
  6. Google Chrome浏览器安装xpath helper插件
  7. 14.data.js
  8. mybatis-sql语句传参
  9. nvelocity的Foreach 中使用DataTable数据
  10. selenium基础(生成测试报告)