NOIp 2009 多项式输出
来源:互联网 发布:淘宝买电器靠谱吗 编辑:程序博客网 时间:2024/05/21 22:34
题目描述
一元 n 次多项式可用如下的表达式表示:
1. 多项式中自变量为x,从左到右按照次数递减顺序给出多项式。
2. 多项式中只包含系数不为0 的项。
3. 如果多项式n 次项系数为正,则多项式开头不出现“+”号,如果多项式n 次项系数为负,则多项式以“-”号开头。
4. 对于不是最高次的项,以“+”号或者“-”号连接此项与前一项,分别表示此项系数为正或者系数为负。紧跟一个正整数,表示此项系数的绝对值(如果一个高于0 次的项,其系数的绝对值为1,则无需输出1)。如果x 的指数大于1,则接下来紧跟的指数部分的形式为“x^b”,其中b 为x 的指数;如果x 的指数为1,则接下来紧跟的指数部分形式为“x”;
如果x 的指数为0,则仅需输出系数即可。
5. 多项式中,多项式的开头、结尾不含多余的空格。
输入
第一行 1 个整数,n,表示一元多项式的次数。
第二行有 n+1 个整数,其中第i 个整数表示第n-i+1 次项的系数,每两个整数之间用空格隔开。
输出
共1 行,按题目所述格式输出多项式。
样例输入
<sample1>5100 -1 1 -3 0 10<sample2>3-50 0 0 1
样例输出
<sample1>100x^5-x^4+x^3-3x^2+10<sample2>-50x^3+1
提示
【数据范围】
1 ≤ n ≤ 100,多项式各次项系数的绝对值均不超过100。
这题略恶心,吃翔去吧。Hail hydra!
#include<cmath>#include<queue>#include<stack>#include<cstdio>#include<vector>#include<string>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>#define MAXN 1000using namespace std;int n,a[MAXN];void init(){cin >> n ;for (int i=1;i<=n+1;i++) scanf("%d",&a[i]);}void Print(int k,int p){bool p1=true,p2=true;if (k == 0) return;if (k > 0 && p!=n) printf("+");if (k < 0) printf("-");if (abs(k) == 1) p1=false;if (p == 1) p2=false;if (p1) printf("%d",abs(k));printf("x");if (p2) printf("^%d",p) ;}int main(){init();for (int i=1;i<=n;i++) Print(a[i],n-i+1);if (a[n+1] == 0) return 0;if (a[n+1] > 0) printf("+%d",a[n+1]);else printf("%d",a[n+1]);return 0;}
0 0
- NOIp 2009 多项式输出
- Noip 2009 1.多项式输出
- NOIP-2009 表达式输出
- 多项式输出
- 多项式输出
- 多项式输出
- 多项式输出
- 多项式输出
- 多项式输出
- 多项式输出
- 多项式输出
- 洛谷1067 多项式输出
- 多项式输出-Java
- [洛谷1067]多项式输出
- 多项式的输出
- 我的多项式输出
- 【p091】多项式输出
- 多项式输出pascal程序
- poj3904 Sky Code【容斥原理】
- 文章标题
- BZOJ-2631 tree Link-Cut-Tree
- IOS开发for循环创建button
- ExpandableListView的用法
- NOIp 2009 多项式输出
- Python碎片小知识点总结
- 201603252026
- Metro(Ural_1119)
- 如何使用BMap.Point传递变量、存储数据?
- 各类缩写总结
- Python环境的安装
- POJ 3468 A Simple Problem with Integers (线段树区间更新模板)
- 网易3.22号笔试(android)