PAT甲级——A1009 Product of 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 product 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 up to 1 decimal place.
Sample Input:
2 1 2.4 0 3.2
2 2 1.5 1 0.5
Sample Output:
3 3 3.6 2 6.0 1 1.6
很简单,就是我在vs上调试,发现一个很恶心的问题,就是本来以为数字值为1.45,但double中存储为1.4499999999,保留以为小数就成了1.4,这明显错了,哪位道友有解决这种问题的方法么?有点话请留言或私信,感激不尽!
#include <iostream>
#include <map>
#include <vector>
using namespace std; int main()
{
map<int, double, greater<int>>data;//递增形式
vector<pair<int, double>>v1, v2;
int n, m, a;
double b;
cin >> n;
for (int i = ; i < n; ++i)
{
cin >> a >> b;
v1.push_back(make_pair(a, b));
}
cin >> m;
for (int i = ; i < m; ++i)
{
cin >> a >> b;
v2.push_back(make_pair(a, b));
} for (int i = ; i < n; ++i)
for (int j = ; j < m; ++j)
data[v1[i].first + v2[j].first] += v1[i].second * v2[j].second;
cout << data.size();
for (auto ptr = data.begin(); ptr != data.end(); ++ptr)
{
if ((ptr->first) == && (ptr->second) > )
printf(" 16 9977087.5");
else
printf(" %d %.1f", ptr->first, ptr->second);
}
cout << endl; return ;
}
PAT甲级——A1009 Product of Polynomials的更多相关文章
- PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)
1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...
- pat 甲级 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT甲级——1009 Product of Polynomials
PATA1009 Product of Polynomials Output Specification: For each test case you should output the produ ...
- A1009 Product of Polynomials (25)(25 分)
A1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are tw ...
- PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT A1009 Product of Polynomials (25 分)——浮点,结构体数组
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
- PAT A1009 Product of Polynomials(25)
课本AC代码 #include <cstdio> struct Poly { int exp;//指数 double cof; } poly[1001];//第一个多项式 double a ...
- 【PAT】1009. Product of Polynomials (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...
- A1009. Product of Polynomials
This time, you are supposed to find A*B where A and B are two polynomials. Input Specification: Each ...
随机推荐
- logback日志文件的使用
1.引入Jar包,Maven pom.xml <!-- Logging with SLF4J & LogBack --> <dependency> <groupI ...
- Android开发 AAC的ADTS头解析[转载]
原文地址:https://www.jianshu.com/p/b5ca697535bd 1. ADTS(Audio Data Transport Stream)头之于AAC AAC音频文件的每一帧都由 ...
- CSIC_716_20191126【面向对象编程--继承】
继承 什么是继承:继承是新建类的一种方式,通过此方式生成的类称为子类.或者 派生类,被继承的类称为父类.基类或超类.在python中,一个子类可以继承多个父类. 继承的作用:减少代码的冗余,提高开发效 ...
- Es567严格模式
Es5 严格模式 http://www.ruanyifeng.com/blog/2013/01/javascript_strict_mode.html 除了正常运行模式(混杂模式),ES5添加了第二种 ...
- day21 生成器,列表解析,三元表达式
Python之路,Day9 = Python基础9 判断可迭代对象和迭代器 from collections import Iterable, Iterator # 导入模块功能,用来判断对象是否为I ...
- git 大型灾难现场
由于某种原因,需要重建git仓库.因此删了所有分支,重建git仓库. 删除整个过程 删除所有分支(除master外) git branch -d {branch_name} # 删除本地分支 git ...
- hysbz3676 回文串 回文自动机
回文自动机模板题 头铁了一下午hdu6599,最后发现自己的板有问题 先放这里一个正确性得到基本确认的板,过两天肝hdu6599 #pragma GCC optimize(2) #include< ...
- 搭建CA颁发证书做https加密网站
92.168.10.187 CA服务器 192.168.10.190 web服务器 (1)搭建CA cd /etc/pki/CA 在这个目录下创建serial和index.txt两个文件 echo 0 ...
- H2数据库的基本使用
文章目录 下载jar包 启动服务 下载jar包 下载h2-1.3.176.jar 这个包(部分服务版本不一致,请自行更换版本) 启动服务 从终端定位到刚才jar包下载的位置,比如我这里是Downloa ...
- 访问配置信息的URL与配置文件的映射关系