https://www.acmicpc.net/problem/12789
한 명씩만 설 수 있는 공간이 매우 스택을 쓰고싶게 생겨서 오랜만에 스택을 써서 구현
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
vector<int> student;
stack<int> temp;
int main() {
int N, input, out = 1, i = 0;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> input;
student.push_back(input);
}
while (1) {
if (i < N && student[i] == out) {
i++;
out++;
}
else if (!temp.empty() && temp.top() == out) {
out++;
temp.pop();
}
else if (i < N) {
temp.push(student[i]);
i++;
}
else if (out > N) {
cout << "Nice";
return 0;
}
else {
cout << "Sad";
return 0;
}
}
}
'ALGORITHM > OTHER' 카테고리의 다른 글
[c++] 14425 문자열 집합 - Trie (트라이), set, unordered_set (0) | 2021.01.24 |
---|---|
2231 분해합, 7568 덩치, 1018 체스판 다시칠하기, 1436 영화감독 숌 (0) | 2021.01.10 |
14621 나만 안되는 연애 (2) | 2021.01.06 |
11585 속타는 저녁 메뉴 (0) | 2020.12.28 |
11582 치킨 TOP N (2) | 2020.12.26 |