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 | #include <stdio.h> #include <stack> using namespace std; int arr[1005] = { 0 }; int main() { int n; scanf("%d", &n); while (1) { stack<int> stk; for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); if (arr[i] == 0) return 0; } int idx = 0; for (int i = 1; i <= n; i++) { stk.push(i); while (stk.top() == arr[idx]) { stk.pop(); idx++; if (stk.empty() == true) break; } } if (stk.empty() == true) printf("Yes\n"); else printf("No\n"); } } | cs |
'알고리즘 > 스텍' 카테고리의 다른 글
9935 문자열 폭발 (0) | 2020.03.12 |
---|---|
10845 큐 (0) | 2019.08.27 |
2605 줄 세우기 (0) | 2019.08.27 |