经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » C » 查看文章
【PAT】A1002 A+B for Polynomials
来源:cnblogs  作者:路明天  时间:2018/10/30 9:00:28  对本文有异议

简单的模拟问题,按照题意一步一步写就好
只要stl用的熟练,这道题非常简单,实在不建议用纯C,这道题就是一个好例子。

  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<set>
  4. using namespace std;
  5. int main(){
  6. float coefficients[1001]={0};
  7. int N;
  8. cin >> N;
  9. set<int> s;
  10. for(int i=0;i<N;i++){//指数做index
  11. int temp;
  12. cin >> temp;
  13. cin >> coefficients[temp];
  14. s.insert(temp);
  15. }
  16. cin >> N;
  17. for(int i=0;i<N;i++){
  18. int temp;
  19. cin >> temp;
  20. float temp1;
  21. cin >> temp1;
  22. coefficients[temp]+=temp1;
  23. if(coefficients[temp]==0) s.erase(temp);
  24. else s.insert(temp);
  25. }
  26. printf("%d",s.size());
  27. for(int i=1000;i>=0;i--){
  28. if(coefficients[i]!=0)
  29. printf(" %d %.1f",i,coefficients[i]);
  30. }
  31. return 0;
  32. }
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号