algorithm'''problem solve
[백준]1874-스택 수열(설명X)
JunHwa Park
2020. 2. 2. 23:40
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 | #include <cstdio> #include <stack> using namespace std; int main() { int n, cur = 1; bool inc = true; scanf("%d", &n); stack<int> stk; stk.push(0); deque<char> c_stk; for (size_t i = 0; i < n; i++) { int num; scanf("%d", &num); if (stk.top() < num) { for (size_t j = cur; j <= num; j++) { c_stk.push_back('+'); stk.push(j); cur++; } stk.pop(); c_stk.push_back('-'); } else if (stk.top() == num) { stk.pop(); c_stk.push_back('-'); } else { printf("NO"); return 0; } } size_t size = c_stk.size(); for (size_t i = 0; i < size; i++) { printf("%c\n", c_stk.front()); c_stk.pop_front(); } return 0; } | cs |