题解——多项式输出

原题:

动态题面查看可还行???

 

其实这题就是特判+特判:

#include <bits/stdc++.h>
using namespace std;
int a[2000001];
int main() {
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    for(int i = 0;i<=n;++i) {
        cin>>a[i];
    }
    bool flag = 0;
    for(int i = 0;i<=n;++i) {
        if(i==0) {
            if(a[i]==1) {
                if(n-i==1) {
                    cout<<"+x";
                    continue;
                }
                cout<<"x^"<<n-i;
                continue;
            }
            if(a[i]==-1) {
                if(n-i==1) {
                    cout<<"-x";
                    continue;
                }
                cout<<"-x^"<<n-i;
                continue;
            }
            cout<<a[i]<<"x^"<<n-i;
            continue;
        }
        if(a[i]==0) {
            continue;
        }
        if(n-i==0) {
            cout<<showpos<<a[i]<<endl;
            break;
        }
        if(a[i]==1) {
            if(n-i==1) {
                cout<<"+x";
                continue;
            }
            cout<<"+x^"<<n-i;
            continue;
        }
        if(a[i]==-1) {
            if(n-i==1) {
                cout<<"-x";
                continue;
            }
            cout<<"-x^"<<n-i;
            continue;
        }
        if(n-i==1) {
            cout<<showpos<<a[i]<<'x';
            continue;
        }
        cout<<showpos<<a[i]<<"x^"<<noshowpos<<n-i;
    }
}

 

  

posted @ 2020-01-20 10:56  littlefrog  阅读(331)  评论(0编辑  收藏  举报