多项式输出50pts求助,大大滴感谢
查看原帖
多项式输出50pts求助,大大滴感谢
645451
封禁用户楼主2023/8/1 19:49
#include <iostream>

using namespace std;

int main() {
	int n, x;
	cin >> n;
	n++;
	cin >> x;
	if (n == 1) {
		cout << x << endl;
		return 0;
	}
	if (x != 1)
		cout << x;
	cout << "x^" << n - 1;
	for (int i = n - 2; i >= 1; i--) {
		cin >> x;
		if (x == 0)
			continue;
		if (x >= 0) {
			cout << "+";

		} else {
			cout << "-";
		}
		if (abs(x ) != 1)
			cout << abs(x);
		cout << "x^" << i;
	}
	cin >> x;
	if (x != 0) {
		if (x >= 0)
			cout << '+';
		cout << x;
	}
	cout << endl;
}
2023/8/1 19:49
加载中...