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 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 (,) 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 ;
}
PAT甲级——A1002 A+B for Polynomials的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- PAT 甲级 1002 A+B for Polynomials
https://pintia.cn/problem-sets/994805342720868352/problems/994805526272000000 This time, you are sup ...
- PAT 甲级1002 A+B for Polynomials (25)
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 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 ...
- 【PAT】A1002 A+B for Polynomials
仅有两个要注意的点: 如果系数为0,则不输出,所以输入结束以后要先遍历确定系数不为零的项的个数 题目最后一句,精确到小数点后一位,如果这里忽略了,会导致样例1,3,4,5都不能通过
- 【PAT甲级】1009 Product of Polynomials (25 分)
题意: 给出两个多项式,计算两个多项式的积,并以指数从大到小输出多项式的指数个数,指数和系数. trick: 这道题数据未知,导致测试的时候发现不了问题所在. 用set统计非零项时,通过set.siz ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
随机推荐
- ECMAScript中所有参数传递的都是值,不可能通过引用传递参数
今天在看JavaScript高级程序设计(第三版)时,看到了这个问题:ECMAScript中所有参数传递的都是值,不可能通过引用传递参数. 在我的印象中,其他语言比如Java,C++等,传递参数有两种 ...
- PostGIS 通过SQL语句实现空间分析【入门级】
PostGIS是对象关系型数据库系统PostgreSQL的一个扩展,PostGIS提供如下空间信息服务功能:空间对象.空间索引.空间操作函数和空间操作符.同时,PostGIS遵循OpenGIS的规范. ...
- pop&dismiss
//dismiss到根视图 - (void)dismissToRootViewController{ UIViewController *vc = self; while (vc.presenting ...
- iOS进阶五-RunLoop
简介 RunLoop 运行循环.跑圈 RunLoop的作用主要体现在三方面: 1.保持程序持续运行 2.处理App中的各种事件(比如触摸事件.定时器事件.Selector事件) 3.节省CPU资源,提 ...
- Linux queue.h之TAILQ队列分析
转自 这两天想看看memcached的实现,所以先学习了libevent,使用起来还是比较简单的,其实是对select/poll/kqueue等的封装,学习libevent过程中又遇到了linux下队 ...
- lock tables和unlock tables
1.lock tables table1 read,table2 read,table3 read igoodful@a8-apple-iphone-db00.wh(glc) > show ta ...
- day20 装饰器补充
Python之路,Day8 = Python基础8 装饰器from functools imoort wraps # 保留原函数所有信息,比如:用__doc__查看注释的时候,显示原来的注释def f ...
- 0916CSP-S模拟测试赛后总结
40分-rank35. 不想找借口.实力不行. 赛时状态没出什么大问题.就是实力太弱了. 天皇又AK了.去问了一下,他说全是简单题…… 后来发现一些人用非正解AC了. 但是天皇题题正解题题首切啊. 还 ...
- mysql索引原理深度解析
mysql索引原理深度解析 一.总结 一句话总结: mysql索引是b+树,因为b+树在范围查找.节点查找等方面优化 hash索引,完全平衡二叉树,b树等 1.数据库中最常见的慢查询优化方式是什么? ...
- char类型在传参时接收不到数据的原因
mybatis的原因!!!!! 数据库这个样子 在postman中调用接口:SQL select * from T_TRAIN_MARSHALLING where TRAIN_NUM is null ...