🔗문제 풀러가기
단계별로 풀어보기 단계 16의 5번째 문제이다.
Stack 컨테이너를 사용해서 문제를 해결하였다.
#include <iostream>
#include <stack>
using namespace std;
int main()
{
stack<int> st;
int n, input, cnt = 1;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> input;
if (input == cnt) cnt++;
else st.push(input);
while (!st.empty() && st.top() == cnt)
{
st.pop();
cnt++;
}
}
if (st.empty()) cout << "Nice";
else cout << "Sad";
}