P1067 [NOIP2009 普及组] 多项式输出(模拟输出细节)

简介: P1067 [NOIP2009 普及组] 多项式输出(模拟输出细节)

Description of the topic



A dollar nn polyn can be represented by an expression such as:

89473a35ba18106421db8067a9e16343.png

f (x)\a_nx=a_ n-1]x=n-1]]cdos=a_1x=a_0,a_n=n=anxn=an=1xn=1=a=a=a0,=0]


Among them, the a_ix is called the secondary term, a_iai is called the coefficient of the secondary. Given the number and coefficient of a unitary polynomial item, output the polynomial as specified in the following format:


  1. The argument in the polynomial is xx, and the polynomial is given from left to right in decreasing order of number of times.
  2. The polynomial contains only items with a factor of not 00.
  3. If the polyn sub-factor is positive, the polynomial does not begin with a "plus" sign, and if the polyn nn sub-factor is negative, the polynomial begins with a "-".


For items that are not the highest, connect the item with the previous item with a "plus" sign or a "-" sign, indicating that the coefficient is positive or negative, respectively. Follow a positive integer that represents the absolute value of the coefficient (if an item is more than 00 times, the absolute value of the coefficient is 11, no output 11 is required). If the index of xx is greater than 11, the index portion that follows is "x-bxb", where bb is the index of xx, if the index of xx is 11, the index part of the index that follows is "xx", and if the index of xx is 00, only the output coefficient is required.


  1. In a polynomial, there are no extra spaces at the beginning or end of the polynomial.


Enter the format



Input common 2 lines


Line 1 integers,n, representing the number of times a single polynomial.


The second line has an integer of n-plus, where the second integer represents the coefficient of the n-i-1 term, separated by a space between each of the two integers.


The output format



The output totals 1 line, output polynomials in the format described in the title.


A sample of the input and output



Enter #1 copy

1. 5 
2. 100 -1 1 -3 0 10


Output #1 copy

100x^5-x^4+x^3-3x^2+10


Enter #2 copy

1. 3 
2. -50 0 0 1


Output #2 copy

-50x^3+1


Description/Tips



NOIP 2009 Popularization Group First Question

For 100% of the data, 0 sle n sle 1000 ≤n≤100, -100 sle s100 ≤ coefficient sle 100≤100

  #include<bits/stdc++.h>
  using namespace std;
  int main()
  {
    int n,m;
    cin>>n;
    for(int i=n;i>=0;i--)
    {
      cin>>m;
      if(m)//把这个为0的情况直接不输出 
      {if(i!=n&&m>0)cout<<"+";//第一位不能有加号 
      if(abs(m)>1||i==0)cout<<m;//m的绝对值不为1和0; 直接输出m 
      if(m==-1&&i)cout<<"-";// 不是最后 一位,把1删掉 
      if(i>1)cout<<"x^"<<i;
      if(i==1)cout<<"x";//特殊化 
      }
    }
   } 


相关文章
|
5月前
【洛谷】P1308 [NOIP2011 普及组] 统计单词数
然后要被查找的b字符串,可能会出现第二个样例中的情况,也就是字符串a是to,而字符串b的Ottoman,这样是不符合题意的。为了 解决这个问题,我们将字符串a首尾都加一个空格,同时将字符串b首尾都加一个空格(这里是为了让字符串b的首单词和尾单词前后均有空格)为了能持续找字符串b中的所有字符串a,我们用一个while循环,如果能找到,就每次从能找到的位置的下一个位置(也就是能找到的位置下标+1)开始找,并及时更新位置,同时计数。因为不区分大小写,所以可以将两个字符串a,b都转为小写(也可以都转为大写)。
137 10
【洛谷】P1308 [NOIP2011 普及组] 统计单词数
|
6月前
|
存储
【洛谷 P2141】[NOIP2014 普及组] 珠心算测验 题解(集合+多重循环)
**NOIP2014普及组的珠心算测验题要求参赛者找出给定集合中多少个数可表示为其他两个不同数的和。输入含n个正整数,输出满足条件的数的个数。样例输入4个数,输出2,因1+2=3且1+3=4。代码利用集合存储和,遍历所有数对组合,当找到匹配和时插入集合,最后输出集合大小。注意数据规模为n≤100,数不超过10,000。**
127 0
|
6月前
|
C++
【洛谷 P1042】[NOIP2003 普及组] 乒乓球 题解(模拟+向量)
`NOIP2003`普及组编程题:乒乓球比赛模拟。给定一系列球赛记录(WL序列),程序需按11分和21分制分析比分。输入含多个字符串,含W(华华得分)、L(对手得分)和E(结束标记)。输出每局比分,分制间空行间隔。样例:`WWWWWW...` → `11:0\n11:0\n1:1`(11分制)和`21:0\n2:1`(21分制)。代码使用C++,逐字符读取,当分差≥2且得分≥x时输出比分。
50 0
Matlab:如何利用层次分析法(升级版)计算具有多重指标的判断矩阵的一致性检验和权重
Matlab:如何利用层次分析法(升级版)计算具有多重指标的判断矩阵的一致性检验和权重
362 0
P1308 [NOIP2011 普及组] 统计单词数(模拟加函数+数学分析)
P1308 [NOIP2011 普及组] 统计单词数(模拟加函数+数学分析)
79 0
P1098 [NOIP2007 提高组] 字符串的展开(模拟分析能力)
P1098 [NOIP2007 提高组] 字符串的展开(模拟分析能力)
103 0
P1093 [NOIP2007 普及组] 奖学金(模拟排序)
P1093 [NOIP2007 普及组] 奖学金(模拟排序)
55 0
【2012NOIP普及组】T1. 质因数分解 试题解析
【2012NOIP普及组】T1. 质因数分解 试题解析
|
机器学习/深度学习 iOS开发 Windows
P2671 [NOIP2015 普及组] 求和(前缀和)
P2671 [NOIP2015 普及组] 求和(前缀和)
145 0
|
Python
Python漫游数学王国 | 总体参数的区间估计
本文讨论总体参数的区间估计。
182 0