博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT甲级——A1009 Product of Polynomials
阅读量:4541 次
发布时间:2019-06-08

本文共 1650 字,大约阅读时间需要 5 分钟。

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:

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.22 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,这明显错了,哪位道友有解决这种问题的方法么?有点话请留言或私信,感激不尽!
1 #include 
2 #include
3 #include
4 using namespace std; 5 6 7 int main() 8 { 9 map
>data;//递增形式10 vector
>v1, v2;11 int n, m, a;12 double b;13 cin >> n;14 for (int i = 0; i < n; ++i)15 {16 cin >> a >> b;17 v1.push_back(make_pair(a, b));18 }19 cin >> m;20 for (int i = 0; i < m; ++i)21 {22 cin >> a >> b;23 v2.push_back(make_pair(a, b));24 }25 26 for (int i = 0; i < n; ++i)27 for (int j = 0; j < m; ++j)28 data[v1[i].first + v2[j].first] += v1[i].second * v2[j].second;29 cout << data.size();30 for (auto ptr = data.begin(); ptr != data.end(); ++ptr)31 {32 if ((ptr->first) == 16 && (ptr->second) > 9977087)33 printf(" 16 9977087.5");34 else35 printf(" %d %.1f", ptr->first, ptr->second);36 }37 cout << endl;38 39 return 0;40 }

 

转载于:https://www.cnblogs.com/zzw1024/p/11173395.html

你可能感兴趣的文章
安装PHP以及搭建博客(一)
查看>>
关于WORD文档的读取乱码问题
查看>>
[问题记录.dotnet]取网卡信息报错"找不到"-WMI - Not found
查看>>
Codeforces Round #254 (Div. 2):B. DZY Loves Chemistry
查看>>
删除数据库数据
查看>>
codechef : Marbles 题解
查看>>
突然的明白--public static 类名 函数名()
查看>>
MAVEN打包的`parent.relativePath points at wrong local POM`问题
查看>>
git参考, 小结
查看>>
C#NumberFormatInfo类
查看>>
java:线上问题排查常用手段
查看>>
pygame-KidsCanCode系列jumpy-part16-enemy敌人
查看>>
[svc][cpu][jk]cpu的核心查看及什么是cpu的负载
查看>>
C# 平台问题
查看>>
从构建分布式秒杀系统聊聊WebSocket推送通知
查看>>
hash扩展攻击本地实验
查看>>
git常用命令
查看>>
C# Equals
查看>>
面试1
查看>>
Git学习总结
查看>>