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. 在mac环境下用QT使用OpenGL,glut,glfw

    只需要在新建工程中.pro文件中添加: #opengl glut LIBS+= -framework opengl -framework glut 就可以使用glut了. 继续添加: ##glfw L ...

  2. css3兼容性问题归纳

    Android2.3的overflow问题 在android2.3及以下系统版本的浏览器不支持overflow:scroll / auto,即在页面元素里面的内容如果超过了父元素或祖先元素的高度是无法 ...

  3. Asp.Net使用百度编辑器(ueditor)

    1.  1.4.3以上版本将不再承诺支持ie6/ie7. 2.如果是aspx 需要加上  ValidateRequest="false" 3.Web.config <syst ...

  4. [转载]如何在C++03中模拟C++11的右值引用std::move特性

    本文摘自: http://adamcavendish.is-programmer.com/posts/38190.htm 引言 众所周知,C++11 的新特性中有一个非常重要的特性,那就是 rvalu ...

  5. if(a==1) & if(1==a) 区别

    [前提] 在公司参加项目时,看到前辈写if比较数值是否相等,经常会写 if(1==a) ,觉得有些奇怪,如是乎,将调查结果写下来记录一下. [结果] if(a==1) 与 if(1==a)是没有什么区 ...

  6. python网络编程-Select\Poll\Epoll异步IO

    首先列一下,sellect.poll.epoll三者的区别 select select最早于1983年出现在4.2BSD中,它通过一个select()系统调用来监视多个文件描述符的数组,当select ...

  7. python网络编程--进程线程

    一:什么是进程 一个程序执行时的实例被称为一个进程. 每个进程都提供执行程序所需的资源.一个进程有一个虚拟地址空间.可执行代码.对系统对象的开放句柄.一个安全上下文.一个独特的进程标识符.环境变量.一 ...

  8. java基础53 IO流技术(转换流)

    1.转换流 1.输入字节的转换流:InputStreamReader是字节流转为字符流的桥梁,可以把输入字节流转换为输入字符流    2.输出字节流的转换流:OutputStreamWriter是字符 ...

  9. Oracle 函数 “数据控制,指定某些人只能查看他权限范围内的信息”

    create or replace function work_plan_mask (p_schema VARCHAR2,p_table VARCHAR2) return Varchar2 AS -- ...

  10. python2.7

    python2.7支持win32.win64 下载地址:http://pan.baidu.com/s/1dE39eQ9 初学,附一个牛人的python教程地址:http://www.liaoxuefe ...