题目

原题大意:求两个多项式的数乘
关键单词对照翻译如下:

exponent 指数 coefficient 系数 polynomial 多项式 product 数乘

思路

  1. 最直接最快速的方法就是使用map,用2个map存储数据,然后用一个map输出结果。
  2. 这道题的坑,我踩到的主要是第一个错误。坑估计如下,这道题是存在最终系数为0(不止一个项)的测试数据,所以必须使用删除系数0项的办法。
  3. 最后用了map的反向定位器,其使用介绍如下,注意要使用反向map容器。
  4. 注释的代码仅仅是为了探测更多测试点的信息,没什么用。

rbegin()

功能:返回一个指向反向 map 容器的第一个元素的定位器。

语法:const_reverse_iterator rbegin()const;

        reverse_iterator rbegin();

说明:rbegin 与反向 map 容器一起使用,它的作用与 map 容器中的 begin 一样。当返回值为一个 const
_reverse _iterator,则 map 容器不会被修改。当返回值为一个 reverse _iterator,则 map 容器可被修改。

函数返回值:返回一个指向反向 map 容器的第一个元素的反向双向定位器。

rend()

功能:返回一个指向反向 map 容器的最后元素后面的定位器。

语法:const_reverse_iterator rend() const;

        reverse_iterator rend();

说明:rend 与反向 map 容器一起使用,它的作用与 map 容器中的 end 一样。当返回值为一个 const _reverse
_iterator,则 map 不会被修改。当返回值为一个 reverse _iterator,则 map 可被修改。

函数返回值:返回一个指向反向 map 容器中的最后一个元素后面的反向双向定位器。

代码

#include <iostream>
#include <map>
#include <cstdio>
using namespace std;
int main(){map<int,float>map1;map<int,float>map2;map<int,float>map3;int n,m;cin>>n;for(int i=0;i<n;i++){int temp;float temp2;cin>>temp>>temp2;map1[temp]=temp2;}cin>>m;for(int i=0;i<m;i++){int temp;float temp2;cin>>temp>>temp2;map2[temp]=temp2;}for(map<int,float>::iterator it=map1.begin();it!=map1.end();it++){for(map<int,float>::iterator jt=map2.begin();jt!=map2.end();jt++){map3[it->first+jt->first]+=it->second*jt->second; }  }// if(map3.size()==1){//      map<int,float>::iterator it=map3.begin();
//      if(it->second==0)
//          cout<<0;
//      else
//          cout<<1;
//  }
//  else
//  cout<<map3.size();for(map<int,float>::iterator i=map3.begin();i!=map3.end();){if(i->second<=1e-15&&i->second>=-1e-15){map3.erase(i);break;}else++i;}cout<<map3.size();for(map<int,float>::reverse_iterator it=map3.rbegin();it!=map3.rend();it++){if(it->second>=1e-5||it->second<=-1e-15)printf(" %d %.1f",it->first,it->second);}return 0;}

第一次写博客,交给pat。

1009 Product of Polynomials (25)(25 分)相关推荐

  1. PAT(Advanced) 1009 Product of Polynomials(25 分)

    2018.9.6 // 注意:一定要计算map中非0的个数,而不能用map.size();#include <iostream> #include <cstdio> #incl ...

  2. PAT甲级1009 Product of Polynomials (25分)

    PAT甲级1009 Product of Polynomials (25分) 题目: 题目分析:和之前有一道多项式相加很像,注意点是不仅仅数组系数会变,还可能会出现之前没有的指数,因此要开2001大小 ...

  3. PAT A1009 Product of Polynomials (25 分)

    A1009 Product of Polynomials (25 分) 前言 Input Specification: Output Specification: Sample Input: Samp ...

  4. PAT甲级1009 Product of Polynomials:[C++题解]多项式乘法、高精度乘法

    文章目录 题目分析 题目链接 题目分析 多项用一个数组来表示,数组下标表示多项式的次幂,存的内容表示多项式的系数. 然后用两重循环来计算多项式的乘法: for i : 第二个式子for j:第一个式子 ...

  5. 「PAT甲级真题解析」Advanced Level 1009 Product of Polynomials

    PAT (Advanced Level) Practice 1009 Product of Polynomials 如果对你有帮助,要点个赞让我知道喔~ 文章目录 问题分析 完整步骤描述 伪代码描述 ...

  6. PAT甲级 -- 1009 Product of Polynomials (25 分)

    This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...

  7. 【测试点0分析】1009 Product of Polynomials (25 分)

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 This time, you are supposed to find A×B where A and B are two pol ...

  8. 1009 Product of Polynomials (25 分)【难度: 简单 / 知识点: 模拟】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805509540921344 注意:系数数据范围虽然是0-1000 但是乘 ...

  9. 【PAT甲级 多项式相乘】1009 Product of Polynomials (25 分) C++ 全部AC

    题目 思路 维护三个数组: arrA[1001]存储第一行数据 arrB[1001]存储第二行数据 c[1000000]存储计算结果 数组下标表示多项式的指数,数组存的内容表示多项式的系数 将arrA ...

最新文章

  1. HDU-1698-Just a Hook
  2. 制药行业的GxP代表什么?
  3. P1569 [USACO11FEB]属牛的抗议Generic Cow Prote…
  4. router OS (ROS)命令中文手册
  5. 彩色图如何转换成灰度
  6. go 捕获数据库新增数据_更改数据捕获的经验教训
  7. 揭开知识库问答KB-QA的面纱4·向量建模篇
  8. 【学习Koa】原生koa2 静态资源服务器例子
  9. python自定义模块与模块调用
  10. java集合的扩容研究
  11. 程序员恶搞图片===爆笑中......娱乐一下.....
  12. Node.js Error: Cannot find module express
  13. python将字典写入txt文件_将一个字典写入txt文件并将其读回来?
  14. Java - @OneToMany注解的mappedBy属性有什么作用?
  15. python 实现读取图片的像素值。
  16. vue组件库开发(npm包发布)
  17. word流程图怎么使箭头对齐_word流程图箭头怎么画
  18. 强智教务系统验证码识别 Tensorflow CNN
  19. 《SQL 入门教程》示例数据库
  20. SQL 保留2位小数的方法/四舍五入

热门文章

  1. Linux(4) 实用指令
  2. 小程序textarea的行间距_微信小程序组件:textarea多行输入框解读和分析
  3. python filter map区别_Python:map()、reduce()、filter()的区别
  4. arraylist从大到小排序_为什么插入排序比冒泡排序更受欢迎?
  5. MySQL服务器地址为空,C++/MySQL - 通过主机地址访问数据库时'未知的MySQL服务器主机';没有IP...
  6. 三级python考试难吗_Python自学之路:三级菜单
  7. 人工智能搭档智能云,进入《西部世界》不是梦!
  8. 第九章、硬件抽象层:HAL
  9. 第一百七十四天 how can i 坚持
  10. 写在前面--点燃酱爆心中的那团火