有什么问题吗?
查看原帖
有什么问题吗?
520775
willix楼主2021/5/16 14:59
#include <iostream>
using namespace std;
int main () {
	int n;
	cin >> n;
	int a[10001] = {};
	for (int i = 1;i <= n+1;i++) {
		cin >> a[i];
	}
	int tmp = 1;
	int cnt = n;
	for (int i = 1;i <= n+1;i++) {
		if (a[i] == 0) {
			cnt--;
			continue;
		}
		else if (a[i] > 0) {
			if (tmp != 1) {
				cout << "+";
			}
		}
		if (a[i] != 1 && a[i] != -1) cout << a[i];
		else if (a[i] == -1) cout << "-";
		if (cnt != 0) {
			cout << "x^" << cnt;
		}
		tmp = 2;
		cnt--;
	}
	return 0;
}

2021/5/16 14:59
加载中...