problem

1002 A+B for Polynomials (25)(25 point(s))
This time, you are supposed to find A+B where A and B are two polynomials. Input Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 a~N1~ N2 a~N2~ ... NK a~NK~, where K is the number of nonzero terms in the polynomial, Ni and a~Ni~ (i=1, 2, ..., K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10,0 <= NK < ... < N2 < N1 <=1000. Output For each test case you should output the sum 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 to 1 decimal place. Sample Input 2 1 2.4 0 3.2
2 2 1.5 1 0.5 Sample Output 3 2 1.5 1 2.9 0 3.2

anwser

#include<iostream>
#include<stdio.h>
#include<iomanip>
#include<cstring> int main()
{
freopen("test.txt", "r",stdin);
float n[1001], n1[1001], n2[1001];
memset(n, 0, 1001*sizeof(float));
memset(n1, 0, 1001*sizeof(float));
memset(n2, 0, 1001*sizeof(float));
int a, b; std::cin>>a;
for(int i = 0; i < a; i++){
int temp1;
float temp2;
std::cin>>temp1>>temp2;
n1[temp1] = temp2;
} std::cin>>b;
for(int i = 0; i < b; i++){
int temp1;
float temp2;
std::cin>>temp1>>temp2;
n2[temp1] = temp2;
} int c = 0;
for(int i = 0; i < 1001; i++){
n[i] = n1[i] + n2[i];
// std::cout<<n[i]<<i<<std::endl;
if(n[i] != 0) c++;
}
std::cout<<c;
for(int i = 1000; i >= 0; i--){
if(n[i] != 0) {
std::cout<<" "<<i<<" ";
std::cout<<std::fixed<<std::setprecision(1)<<n[i];
// printf("%.1f", n[i]);
}
}
return 0;
} /*
2 1 2.4 0 3.2
2 2 1.5 1 0.5
*/

experience

  • 注意头文件名
  • 注意边界条件以及输出格式

单词复习:

  • polynomials 多项式
  • exponents 范例,指数
  • coefficients 系数
  • respectively 分别的
  • accurate 精确的
  • decimal 小数

最新文章

  1. ffmpeg编译参数详解
  2. php mb_convert_encoding的使用
  3. Shader Model 版本与DirectX的关系(OpenGL对应的呢?)
  4. Objective C 基础
  5. 关闭WordPress自动加载的Open Sans字体-WP访问过慢原因
  6. UILabel 根据内容的多少来计算label的frame
  7. 前Google人谈团队管理:针对不同员工的情境管理法和如何选择合理的团队规模
  8. zoj 1409 Communication System
  9. JSP之项目路径问题(${pageContext.request.contextPath},&lt;%=request.getContextPath()%&gt;以及绝对路径获取)
  10. hadoop集群的搭建与配置(1)
  11. Area 使用
  12. Codeforce 854 A. Fraction
  13. 我对asp.net运行机制的理解
  14. Robot Framework脚本在jenkins执行完之后无法查看日志
  15. java 发邮件
  16. android studio导出apk
  17. day 42 mycql 查询操作,重点中的重点
  18. ajax异步请求302
  19. MacDev.GarbageCollectionIsDeprecated-WhenXcodeCompileMacAppProject
  20. Linux系统的vi命令

热门文章

  1. phpexcel 导入导出excel表格
  2. 关于初次使用Linux的一些小经验
  3. Windows无法访问局域网内共享文件夹[0x800704cf,0x80070035]解决方案
  4. JDk1.8源码StringBuffer
  5. 关于oracle数据库死锁的检查方法
  6. C# WebClient进行FTP服务上传文件和下载文件
  7. gitHub 迁移到gitlab上
  8. Vue 进阶教程之:详解 v-model
  9. go语言版本变化
  10. idea心得