P1067

  这题没什么好说的,就是判断,需要考虑仔细一点。

  AC代码

#include <bits/stdc++.h>
using namespace std;
const int N = 712;
int main()
{
    stringstream eq;
    int coe[N];
    int n;
    cin >> n;
    memset(coe, -1, sizeof(coe));
    for (int i = 0; i <= n; i++)
        cin >> coe[i];
    for (int i = 0; i <= n; i++)
    {
        if (coe[i] == 0)
        {
            if (coe[i + 1] > 0)
                eq << "+";
            continue;
        }
        if (coe[i] != 1 && coe[i] != -1 && i != n)
            eq << coe[i];
        if (coe[i] == -1 && i != n)
            eq << '-';
        if (i < n - 1)
            eq << "x^" << n - i;
        else if (i != n)
            eq << 'x';
        else
            eq << coe[i];
        if (coe[i + 1] > 0)
            eq << "+";
    }
    cout << eq.str() << endl;
    return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/darkchii/p/9670971.html