呜呜呜呜呜,50的魔咒逃不出了,救救我

P1067 [NOIP2009 普及组] 多项式输出

OTH_chinese_dragon @ 2024-10-24 18:27:17

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int y=0;
    for(int i=1; i<=n+1; i++){
        int x;
        cin>>x;
        if(x!=0) y++;
        if(x==0) continue;
        if(x > 0 && n-i+1 != n && y != 1){ cout<<"+";}
        if(x < 0 && n-i+1 != 0){cout<<"-"; }
        if(abs(x) != 1 && n-i+1 != 0) {cout<<abs(x);}
        else if(n-i+1 == 0){cout<<abs(x); continue;}
        if(n-i+1 != 1) cout<<"x^"<<n-i+1;
        else if(n-i+1 == 1) cout<<"x";

    }  
    return 0;
}

by FishPressedCoins @ 2024-10-31 23:12:42

#include<iostream>
#include<cmath>
using namespace std;
int N, t;
int main()
{
    cin >> N;
    for (int i = 0, j = 0; i <= N; i++)
    {

        cin >> t;
        if (t)
        {
            if (j != 0 && t > 0)cout << '+';
            if (t == -1)cout << '-';
            if (abs(t) != 1 || i == N)cout << t;
            if (i < N - 1)cout << "x^" << N - i;
            if (i == N - 1)cout << 'x';
            j++;
        }
    }
    return 0;
}

|