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 小数

1002 A+B for Polynomials (25)(25 point(s))的更多相关文章

  1. PAT甲级 1002 A+B for Polynomials (25)(25 分)

    1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...

  2. A1002 A+B for Polynomials (25)(25 分)

    1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...

  3. PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)

    1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...

  4. A1009 Product of Polynomials (25)(25 分)

    A1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are tw ...

  5. MySQL5.7.25(解压版)Windows下详细的安装过程

    大家好,我是浅墨竹染,以下是MySQL5.7.25(解压版)Windows下详细的安装过程 1.首先下载MySQL 推荐去官网上下载MySQL,如果不想找,那么下面就是: Windows32位地址:点 ...

  6. PAT 甲级 1006 Sign In and Sign Out (25)(25 分)

    1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...

  7. 【PAT】1020 Tree Traversals (25)(25 分)

    1020 Tree Traversals (25)(25 分) Suppose that all the keys in a binary tree are distinct positive int ...

  8. 【PAT】1052 Linked List Sorting (25)(25 分)

    1052 Linked List Sorting (25)(25 分) A linked list consists of a series of structures, which are not ...

  9. 【PAT】1060 Are They Equal (25)(25 分)

    1060 Are They Equal (25)(25 分) If a machine can save only 3 significant digits, the float numbers 12 ...

随机推荐

  1. datagrid时间插件

    jquery easyui日期控件中,在页面里用JS拿到设立的日期值的方法 链接:http://blog.csdn.net/liweibin_/article/details/13509917 jqu ...

  2. spring断言使用

    断言就是断定某一个实际的值为自己预期想得到的,如果不一样就抛出异常. Assert经常用于: 1.判断method的参数是否属于正常值.2.juit中使用. import org.springfram ...

  3. sklearn评估模型的方法

    一.acc.recall.F1.混淆矩阵.分类综合报告 1.准确率 第一种方式:accuracy_score # 准确率import numpy as np from sklearn.metrics ...

  4. Hive笔记之导出查询结果

    一.导出到本地 导出查询结果到本地: INSERT OVERWRITE LOCAL DIRECTORY "/tmp/hive-result/t_visit_video" SELEC ...

  5. Python练习-装饰器版-为什么我的用户总被锁定

    参考代码如下: 1.用户登录程序流程控制代码: # 编辑者:闫龙 if __name__ == '__main__': import UserLoginFuncation LoclCount=[]; ...

  6. Esper复杂事务处理一小时入门

    来自小韩 什么是Esper 想要认识Esper,先要了解CEP(Complex Event Processing),到处都有,并且各方理解也有偏差,我就不赘述了. Esper就是CEP的一个java的 ...

  7. python内置模块之itertools

    前言 itertools模块是python内置的迭代器模块,定义了可生成多种迭代器的函数,用来代替可迭代对象的遍历等操作,节约内存. 迭代器函数的类型 无限迭代器:包括count.cycle.repe ...

  8. 一步一步搭建11gR2 rac+dg之配置单实例的DG(八)【转】

    RAC主库配置单实例ActiveDataguard 本文文档结构: 这里配置的过程中需要注意的一项是多看看rac1和rac2以及dg的告警日志会对配置过程有更深刻的理解...配置oracle rac的 ...

  9. c++语言知识点汇总

    c++ primer version-5 的整理 section 1: 内置类型和自定义类型: main函数的返回值:指示状态.0:成功:1:系统定义. unix和win系统中,执行完程序可以使用ec ...

  10. jQuery-选择器-查找标签

    一.jQuery选择器 jQuery选择器就是帮助我们快速定位到一个或多个DOM节点 1.1  ID选择器 如果某个DOM节点有id属性,利用jQuery查找方式: <script src=&q ...