50分求调
查看原帖
50分求调
561638
Tanhaoyue2011楼主2025/7/25 15:49
#include<iostream>

using namespace std;

int n,a[105],cnt;
int main(){
    cin >> n;
    for(int i = 1; i <= n + 1; i++){
        cin >> a[i];
    }
    cnt = n;
    for(int i = 1; i <= n + 1; i++){
        if(a[i] > 0){
            if(cnt == n){
                if(a[i] == 1) cout << "x^" << cnt;
                else cout << a[i] << "x^" << cnt;
            } else if(cnt != 1){
                if(a[i] == 1) cout << "+x^" << cnt;
                else cout << "+" << a[i] << "x^" << cnt;
            } else {
                cout << "+" << a[i] << endl;
            }
           cnt--;
        } else if(a[i] == 0){
            cnt--;
            continue;
        } else {
            if(cnt != 1){
                if(a[i] == -1) cout << "-x^" << cnt;
                else cout << a[i] << "x^" << cnt;
            } else {
                cout << a[i] << endl;
            }
            cnt--;
        }
    }
    return 0;
}
2025/7/25 15:49
加载中...