PAT甲级——A1009 Product of Polynomials
2024-10-07 22:57:03
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 ;
}
最新文章
- F#之旅9 - 正则表达式
- [译]App Framework 2.1 (1)之 Quickstart
- C++指针和动态内存分配
- 转:ProgressMonitorDialog
- 用ccproxy + stunnel做个加密代理
- Jqgrid 数据格式化配置
- 20135214万子惠 (2)——-Java面向对象程序设计
- HDU 5534 Partial Tree 完全背包
- 《Ruby语言入门教程v1.0》学习笔记-02
- 搭建Struts2开发环境
- Mysql 新建用户以及授权远程连接操作
- trailingZeroes
- TreeMap cannot be cast to java.lang.Comparable
- javaScript 设计模式系列之三:代理模式
- 2101: Bake Off
- PyCharm调试运行Scrapy教程
- android开发 一个更优的listView的写法
- ApplicationContext(四)BeanFactory 功能扩展
- [Spark Core] Spark Shell 实现 Word Count
- Eclipse导入Android项目的方法(转)