博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
甲级1002 A+B for Polynomials (25)
阅读量:4570 次
发布时间:2019-06-08

本文共 1408 字,大约阅读时间需要 4 分钟。

题目描述:

This time, you are supposed to find A+B where A and B are two polynomials.InputEach 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.OutputFor 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 Input2 1 2.4 0 3.22 2 1.5 1 0.5Sample Output3 2 1.5 1 2.9 0 3.2@:polynomial    多项式 exponents     指数 coefficients  系数

 

 

题目要求:

给出俩个多项式的指数和系数,没有给出基数,只要将指数相同的多项式进行系数相加即可。输出时按照指数从高到低的顺序输出。

注意题意,一开始没有看题意直接看的实例,忽略了负数情况相加之后系数可能为零从而不写,所以常用的单词还是得认得。。。

 

代码:

#include 
#include
#include
#include
#include
using namespace std;int main(){ int i,j,a,n; int con=0; double s[1200],b; int vis[1200]; memset(s,0,sizeof(s)); memset(vis,0,sizeof(vis)); for(i=0;i<2;i++) { scanf("%d", &n); for(j=0;j
=0;i--) if(s[i]!=0) printf(" %d %.1f",i,s[i]); printf("\n"); return 0;}

 

转载于:https://www.cnblogs.com/weiyuan/p/7153700.html

你可能感兴趣的文章
面试题8:二叉树下的一个节点
查看>>
hash冲突的解决方法
查看>>
Asp.Net webconfig中使用configSections的用法
查看>>
mysql 二进制日志
查看>>
阻止putty变成inactive
查看>>
TP框架代码学习 学习记录 3.2.3
查看>>
doc文档生成带目录的pdf文件方法
查看>>
js数组,在遍历中删除元素(用 for (var i in arr)是无效的 )
查看>>
通过前端上传图片等文件的方法
查看>>
在 OC 中调用 Swift 代码
查看>>
Android仿腾讯应用宝 应用市场,下载界面, 有了进展button
查看>>
安卓|五大逆向软件下载
查看>>
5 OK6410裸机调试(不用Jlink)
查看>>
“模板”学习笔记(5)-----编译器在处理函数模板的时候都干了啥
查看>>
教你用shell写CGI程序
查看>>
窗口 对话框 Pop Dialog 示例
查看>>
ubuntu(centos) server安装vmware tools
查看>>
数据结构之最大不重复串
查看>>
为什么要配置sdk-tools/platform-toools?
查看>>
自己动手开发更好用的markdown编辑器-07(扩展语法)
查看>>