1002. A+B for Polynomials (25) (浮点数判0)
2024-09-30 18:54:48
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 aN1 N2 aN2 ... NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (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
这题翻译过来其实就是多项式加法
#include<stdio.h>
#include<stdlib.h>
#include<math.h> int main()
{
int n;
int i,j;
double xi;
int zi;
double a[];
int cnt=; for( i=;i<; i++)
{
a[i] = ;
}
for( i=; i<; i++){
scanf("%d",&n);
for( j=; j<n; j++){
scanf("%d %lf",&zi,&xi);
a[zi] += xi;
}
} for( i=; i>=; i--){
if( fabs(a[i])>1e-)
cnt++;
}
printf("%d",cnt);
for( i=; i>=; i--){
if( fabs(a[i])>1e-)
printf(" %d %.1lf",i,a[i]);
} return ;
}
最新文章
- Linux查看物理CPU个数、核数、逻辑CPU个数
- 【url重写】
- UIImagePickerController在ios10环境一打开就crash的问题
- Linux安装Redis
- 服务器端验证--验证框架验证required.
- Git 分支管理是一门艺术
- 搭建linux下teamspeak3多人语音服务器
- 《JS权威指南学习总结--1.1语言核心》
- 利用TinyXml进行数据库的热更新
- winserver-查看登陆日志
- windows cannot find powershell.exe windows 7
- linux上安装mysql5.6
- 【翻译】FluentValidation验证组件的使用
- XML注释与取消注释快捷键
- WebAPi获取请求头中对应键值
- TabLayout+ViewPager的简单使用
- django 的用户验证及登录状态保持
- SQL函数汇总(MySQL教材)
- 【Android】7.2 LinearLayout(线性布局)
- HDU1160FatMouse&#39;s Speed