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. thinkphp 修改分页样式表

    原网页:http://blog.csdn.net/u014175572/article/details/53116546 在这里我有先把page的设置做成了一个函数getpage, 将这个方法放到Ap ...

  2. linux下lz4解压缩遇到的那些事儿

    一.Debian系列:Debian.Ubuntu等1.1 kali下修改apt-get源:   vim /etc/apt/sources.list     deb http://mirrors.ust ...

  3. 网站发布IIS后堆栈追踪无法获取出错的行号

    一.问题起因 系统发布上线后,有时会发生错误,那么错误的记录就很重要,它对于错误的排查和问题的发现有着重要的作用,通常我们采取的方式为Log日志文件记录和数据库错误记录.文本不会讨论错误记录的方式以及 ...

  4. 【自用】bat ftp下载前一天备份

    @echo off rem 指定FTP用户名 set ftpUser=app rem 指定FTP密码 set ftpPass=app rem 指定FTP服务器地址 set ftpIP=192.168. ...

  5. 四、Springboot Debug调试

    描述: 在使用maven插件执行spring-boot:run进行启动的时候,如果设置的断点进不去,要进行以下的设置. 1.添加jvm参数配置 在spring-boot的maven插件加上jvmArg ...

  6. pyquery学习笔记

    很早就听说了pyquery的强大.写了个简单的测试程序实验下. 思路是找个动态网页,先用PhantomJS加载,然后用PYQUERY解析. 1.随便找了个带表格的股票网页,里面有大量的股票数据,测试的 ...

  7. day07作业

    import java.util.Scanner; class SsqGame { public static void main(String[] args) { int total = 0;//买 ...

  8. 虚拟机 CentOS7 64

    下载地址:https://www.centos.org/download/ 下载完后以后使用虚拟机安装即可

  9. tomcat运行内存溢出问题

    tomcat 运行内存配置优化 /opt/apache-tomcat-7.0.65/bin/catalina.sh:JAVA_OPTS="$JAVA_OPTS -Dfile.encoding ...

  10. delphi 获取一个字符占用几个字节,方法