-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboj1874.cpp
63 lines (56 loc) · 857 Bytes
/
boj1874.cpp
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
60
61
62
63
#include<iostream>
#include<algorithm>
#include<stack>
#include<vector>
using namespace std;
int main()
{
bool isCompatible = true;
stack<int> s;
vector<int> v;
vector<char> c;
int n, val = 1, idx = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
int tmp;
cin >> tmp;
v.push_back(tmp);
}
while (true)
{
if (idx == n) break;
if (v[idx] >= val) // v = [4 3 6 8 7 5 2 1], idx = 0~7, val = 1~8
{
s.push(val++);
//cout << "+" << endl;
c.push_back('+');
}
else if (v[idx] < val) // v = [4 3 ...], idx=4 -> v[]=
{
if (s.top() == v[idx])
{
s.pop();
//cout << "-" << endl;
c.push_back('-');
idx++;
}
else
{
isCompatible = false;
break;
}
}
}
if (isCompatible)
{
for (int i = 0; i < c.size(); i++)
{
cout << c[i];
cout << "\n";
}
}
else
cout << "NO";
return 0;
}