'commit'
This commit is contained in:
48
TangDou/LuoGuBook/第8章模拟与高精度/P1067_2.cpp
Normal file
48
TangDou/LuoGuBook/第8章模拟与高精度/P1067_2.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
/*
|
||||
5
|
||||
100 -1 1 -3 0 10
|
||||
*/
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
int a;
|
||||
for (int i = 0; i < n; i++) {
|
||||
cin >> a;
|
||||
if (a > 0) {
|
||||
if (i > 0) cout << "+";
|
||||
if (a > 1) {
|
||||
if (n - i == 1)
|
||||
cout << a << "x";
|
||||
else
|
||||
cout << a << "x^" << n - i;
|
||||
} else {
|
||||
if (n - i == 1)
|
||||
cout << "x";
|
||||
else
|
||||
cout << "x^" << n - i;
|
||||
}
|
||||
|
||||
} else if (a < 0) {
|
||||
if (a == -1) {
|
||||
if (n - i == 1)
|
||||
cout << "-x";
|
||||
else
|
||||
cout << "-x^" << n - i;
|
||||
} else {
|
||||
if (n - i == 1)
|
||||
cout << a << "x";
|
||||
else
|
||||
cout << a << "x^" << n - i;
|
||||
}
|
||||
}
|
||||
}
|
||||
cin >> a;
|
||||
if (a > 0)
|
||||
cout << "+" << a << endl;
|
||||
else if (a < 0)
|
||||
cout << a << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user