This repository was archived by the owner on May 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1067.cpp
More file actions
54 lines (53 loc) · 1.53 KB
/
P1067.cpp
File metadata and controls
54 lines (53 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// Created by RenAhsAcme on 2026/4/19.
//
#include <iostream>
#include <vector>
using namespace std;
int main() {
int tmp = 0;
cin >> tmp;
int n = tmp + 1;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
bool has_first = false;
for (int i = 0; i < n; i++) {
if (a[i] == 0) continue;
if (!has_first && a[i] != 0) {
if (n - 1 - i == 0) {
cout << a[i];
return 0;
}
if (n - 1 - i == 1)
if (a[i] == 1) cout << "x";
else if (a[i] == -1) cout << "-x";
else cout << a[i] << "x";
else if (a[i] == 1) cout << "x^" << n - 1 - i;
else if (a[i] == -1) cout << "-x^" << n - 1 - i;
else cout << a[i] << "x^" << n - 1 - i;
has_first = true;
continue;
}
if (has_first && i == n - 1) {
if (a[i] > 0) cout << "+" << a[i];
else cout << a[i];
break;
}
if (has_first && n - 1 - i == 1) {
if (a[i] > 0)
if (a[i] != 1) cout << "+" << a[i] << "x";
else cout << "+x";
else cout << a[i] << "x";
continue;
}
if (a[i] > 0) {
if (a[i] == 1) cout << "+x^" << n - 1 - i;
else cout << "+" << a[i] << "x^" << n - 1 - i;
}
if (a[i] < 0) {
if (a[i] == -1) cout << "-x^" << n - 1 - i;
else cout << a[i] << "x^" << n - 1 - i;
}
}
return 0;
}