-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_Array_bj.cpp
More file actions
59 lines (55 loc) · 993 Bytes
/
Copy pathStack_Array_bj.cpp
File metadata and controls
59 lines (55 loc) · 993 Bytes
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
55
56
57
58
59
// baekjoon - 1874
#include <iostream>
#include <vector>
using namespace std;
bool pos;
int n, num, n_count, len;
vector<int>n_arr;
vector<int>stack;
vector<char>pupo;
int main() {
pos = true;
cin >> n;
for (int i{ 1 }; i < n+1; i++) {
cin >> num;
n_arr.push_back(num);
}
for (int i{ 1 }; i < n + 1; i++) {
stack.push_back(i);
pupo.push_back('+');
if (n_arr[n_count] == i) {
stack.pop_back();
pupo.push_back('-');
n_count++;
if (n_count != n && stack.size() != 0) {
for (int j{ i - 1 }; j > 0; j--) {
if (n_arr[n_count] == j) {
stack.pop_back();
pupo.push_back('-');
n_count++;
}
}
}
}
}
len = stack.size();
for (int i{ 0 }; i < len; i++) {
if (n_arr[n_count] == stack[len-1]) {
stack.pop_back();
pupo.push_back('-');
n_count++;
pos = true;
}
else {
pos = false;
}
}
if (pos == false) {
cout << "NO\n";
}
else {
for(int i{0}; i < pupo.size() ; i++) {
cout << pupo[i] << "\n";
}
}
}