Polynomial_0
@【注】两个一元多项式按照指数由大到小的顺序输入!
#include <stdio.h> #define MAXSIZE 50 struct PolyNode
{
int coefficient;
int exponential;
}; int main()
{
PolyNode a[MAXSIZE];
PolyNode b[MAXSIZE];
PolyNode c[2*MAXSIZE];
int n1, n2;
scanf("%d", &n1);
int i;
for(i=0; i<n1; ++i)
scanf("%d %d", &a[i].coefficient, &a[i].exponential);
scanf("%d", &n2);
int j;
for(j=0; j<n2; ++j)
scanf("%d %d", &b[j].coefficient, &b[j].exponential);
int ind=0;
for(i=0, j=0; (i<n1)&&(j<n2); )
{
if(a[i].exponential>b[j].exponential)
{
c[ind].exponential=a[i].exponential;
c[ind].coefficient=a[i].coefficient;
++i;
}
else if(a[i].exponential<b[j].exponential)
{
c[ind].exponential=b[j].exponential;
c[ind].coefficient=b[j].coefficient;
++j;
}
else
{
c[ind].exponential=a[i].exponential;
c[ind].coefficient=a[i].coefficient+b[j].coefficient;
++i;
++j;
}
++ind;
}
while(i<n1)
{
c[ind].exponential=a[i].exponential;
c[ind].coefficient=a[i].coefficient;
++i;
++ind;
}
while(j<n2)
{
c[ind].exponential=b[j].exponential;
c[ind].coefficient=b[j].coefficient;
++j;
++ind;
}
printf("f(x)=");
for(i=0; i<ind; ++i)
{
if(c[i].coefficient>1)
{
if(i!=0)
printf("+");
printf("%dx^%d", c[i].coefficient, c[i].exponential);
}
else if(c[i].coefficient==1)
{
if(i!=0)
printf("+");
printf("x^%d", c[i].exponential);
}
else if(c[i].coefficient==0)
;
else if(c[i].coefficient==-1)
printf("-x^%d", c[i].exponential);
else
printf("%dx^%d", c[i].coefficient, c[i].exponential);
}
printf("\n");
return 0;
}
Polynomial_0的更多相关文章
随机推荐
- Javascript我学之三函数的参数
本文是金旭亮老师网易云课堂的课程笔记,记录下来,以供备忘 函数的参数 对于参数值,JavaScript不会进行类型检查,任何类型的值都可以被传递给参数. ...
- Redis数据类型Hash
Redis的Hash有点像一个对象(object),一个Hash里面可以存多个Key-Value对作为它的field,所以它通常可以用来表示对象.Hash里面能存放的值也能作为String类型来存储, ...
- jQuery中height()不能精确计算的问题
jQuery中关于高度的计算有三个方法:outerHeight().innerHeight().height() outerHeight():获取元素集合中第一个元素的当前计算高度值,包括paddin ...
- jupyter notebook 远程访问
https://www.youtube.com/watch?v=LpQl0yeZzCU 在服务器端执行: jupyter notebook --ip 服务器的Ip地址 --allow-root --n ...
- 2017-2018 Northwestern European Regional Contest (NWERC 2017)
A. Ascending Photo 贪心增广. #include<bits/stdc++.h> using namespace std; const int MAXN = 1000000 ...
- NOIP-无线网路发射器选址
题目描述 随着智能手机的日益普及,人们对无线网的需求日益增大.某城市决定对城市内的公共场所覆盖无线网. 假设该城市的布局为由严格平行的129条东西向街道和129条南北向街道所形成的网格状,并且相邻的平 ...
- 转 MYSQL InnoDB Record, Gap, and Next-Key Locks
http://dev.mysql.com/doc/refman/5.0/en/innodb-record-level-locks.html InnoDB has several types of re ...
- SSM的 日常错误 之 mybatis
HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemExc ...
- 论Photoshop的正确安装姿势
Adobe Photoshop 俗称 PS 专业的平面设计软件之一,是Adobe公司最最最牛逼的软件之一.入门很容易,但是想掌握高超的修图,仅靠后天99%的努力是没用的,设计这个东西,讲到底需要的是灵 ...
- checkbox 用css改变默认的样式
<!--html--> <label class="bl_input_checkbox click_checkbox" che_data="10&quo ...