Files
python/TangDou/LuoGuBook/第8章模拟与高精度/P1067.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

37 lines
921 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
//这模拟太啰嗦了~
int main() {
int n;
cin >> n;
int x;
// a[0~n-1]是系数,a[n]是常数
for (int i = 0; i < n; i++) {
cin >> x;
if (x == 0) continue;
if (x < 0) {
if (x == -1)
cout << "-";
else
cout << x; //-1不要输出1,其它的-2,-3等如实输出
} else { // x肯定大于0
if (i > 0) cout << "+"; //第一位前面不能有+号
if (x != 1) cout << x; //系数1不输出,2,3等正常输出
}
if (n - i > 1) cout << "x^" << n - i;
else
cout << "x"; // 1次方特殊
}
//常数位
cin >> x;
if (x > 0)
cout << "+" << x;
else if (x < 0)
cout << x;
return 0;
}