题解
2023-08-16 20:50:18
发布于:广东
2阅读
0回复
0点赞
话不多说,请看题解~
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    
    int a[n+1];
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
    }
    
    bool flag = true;
    for (int i = 0; i <= n; i++) {
        if (a[i] != 0) {
            if (flag) {
                flag = false;
                
                if (a[i] == -1 && i != n) {
                    cout << "-";
                } else if (a[i] != 1 || i == n) {
                    cout << a[i];
                }
            } else {
                if (a[i] > 0) {
                    cout << "+";
                } else {
                    cout << "-";
                }
                
                if (a[i] != 1 && a[i] != -1 || i == n) {
                    cout << abs(a[i]);
                }
            }
            
            if (i != n) {
                cout << "x";
                
                if (i != n-1) {
                    cout << "^" << n-i;
                }
            }
        }
    }
    
    return 0;
}
这里空空如也


有帮助,赞一个