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 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 ;
}

最新文章

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

热门文章

  1. iOS进阶一OC对象的本质
  2. Linux 实用指令(9)--进程管理
  3. The linux command 之进程
  4. 安装Epson打印机但因lsb依赖错误而中断的驱动程序
  5. centos lamp笔记
  6. 微信公众号支付出现:“当前页面的URL未注册”
  7. 初识 HTML
  8. LUOGU P2860 [USACO06JAN]冗余路径Redundant Paths (双联通,缩点)
  9. badboy录制添加检查点
  10. 存储过程被程序和第三方客户端执行很慢,而sql server management studio执行速度正常