-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaekJoon1874.cpp
More file actions
56 lines (45 loc) · 754 Bytes
/
BaekJoon1874.cpp
File metadata and controls
56 lines (45 loc) · 754 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
//BaekJoon 1874 스택 수열
#include <iostream>
#include <string>
using namespace std;
int stack[100000];
int top = 0;
char* result;
int pointer = 0;
void push(int num) {
stack[top++] = num;
result[pointer++] = '+';
}
int pop() {
result[pointer++] = '-';
return stack[--top];
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int n = 0;
cin >> n;
result = new char[n];
int max = 0;
while (n--) {
int tmp = 0;
cin >> tmp;
if (max < tmp) {
for (int i = max + 1; i <= tmp; i++) {
push(i);
}
}
else {
if (stack[top - 1] != tmp) {
cout << "NO" << "\n";
return 0;
}
}
pop();
if (max < tmp) max = tmp;
}
for (int i = 0; i < pointer; i++) {
cout << result[i] << "\n";
}
return 0;
}