A+B for Polynomials
2024-10-20 05:30:13
This time, you are supposed to find A+B where A and B are two polynomials.
Input Specification:
Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:
K N1 aN1 N2 aN2 ... NK aNK
where K is the number of nonzero terms in the polynomial, Ni and aNi (,) are the exponents and coefficients, respectively. It is given that 1,0.
Output Specification:
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
#include<iostream>
using namespace std;
int main(){
int m,n,i,temp,count=0;
float a[1002],b[1002];
cin>>m;
for(i=0;i<m;i++){
cin>>temp;
cin>>a[temp];
}
cin>>n;
for(i=0;i<n;i++){
cin>>temp;
cin>>b[temp];
if(a[temp]==0){
a[temp]=b[temp];
}
else{
a[temp]+=b[temp];
}
}
for(i=0;i<1001;i++){
if(a[i]!=0)
count++;
}
cout<<count;
for(i=1000;i>=0;i--){
if(a[i]!=0){
printf(" %d %.1f",i,a[i]);
}
}
return 0;
}
最新文章
- Unity依赖注入使用
- centOS安装nginx
- 2015年第3本(英文第2本):Daughter of Deceit
- 如何将NTFS格式的移动硬盘挂接到Mac OS上进行读写(Read/Write)操作
- codefoces round193a
- RHEL安装docker-compose
- Matlab中imshow()函数的使用
- Unity3d 协程、调用函数、委托
- ruby编程语言-学习笔记3(第4章 表达式和操作符)
- 减少 WAF 漏报的 8 种方法 !
- [置顶] Guava学习之Lists
- 在Android手机上获取其它应用的包名及版本
- android开发进阶学习博客资源
- 如何使用LIBSVM,从安装到基本实例使用
- ssh框架-Struts2(二)
- QT中对内存的管理
- django websocket
- 关于 atcoder 页面美化的 css
- ES5之函数的间接调用 ( call、apply )、绑定 ( bind )
- IOS绘图详解
热门文章
- Spring源码窥探之:扩展原理BeanDefinitionRegistryPostProcessor
- Java代码写PDF-保全批单
- 15-Flutter移动电商实战-商品推荐区域制作
- learning armbian steps(11) ----- armbian 源码分析(六)
- C# list常用的几个操作 改变list中某个元素的值 替换某一段数据
- select count(1)和 select count(*)
- Noip2019暑期训练2 反思
- leetcode 删除一张表中重复邮箱的数据,并且保留最小id 的 那条
- Win7下安装VS2017、安装Qt5.10.1以及在VS2017添加qt插件
- deepin深度学习环境配置