백준 12789
Algorithm2023. 8. 19. 17:52
그래도 스택 자료구조는 한번 해봐야 하지 않을까? 해서 풀어본 문제
정답률이 꽤 낮아 풀어봤다.
아마 사이드에 빠졌다가 원래 있던 줄로 다시 돌아갈 수 없는데,
돌아갈 수 있다고 착각해서 틀린 나같은 사람이 많아서 정답률이 낮은것 같다.
https://www.acmicpc.net/problem/12789
12789번: 도키도키 간식드리미
인하대학교 학생회에서는 중간, 기말고사 때마다 시험 공부에 지친 학우들을 위해 간식을 나눠주는 간식 드리미 행사를 실시한다. 승환이는 시험 기간이 될 때마다 간식을 받을 생각에 두근두
www.acmicpc.net
using System;
using System.Collections.Generic;
using System.Net;
namespace Snack_Line
{
class b12789
{
static string solution(Stack<int> num)
{
Stack<int> side = new Stack<int>();
int check = 1;
while(true)
{
if (num.Contains(check)){
int tmp = 0;
while (check != (tmp = num.Pop()))
{
side.Push(tmp);
}
//Console.WriteLine(tmp);
}
else if (side.Contains(check))
{
while (true)
{
int tmp = side.Pop();
//Console.WriteLine(tmp);
if (check != tmp)
{
return "Sad";
}
//if(side.Count == 0)
//{
// break;
//}
break;
}
}
else
{
return "Sad";
}
if ((num.Count == 0) && (side.Count == 0))
{
return "Nice";
}
check++;
//break;
}
}
static void Main(string[] args)
{
int N = int.Parse(Console.ReadLine());
string[] tmp = Console.ReadLine().Split(' ');
Stack<int> number = new Stack<int>();
for(int i = N-1; i >= 0; i--)
{
number.Push(int.Parse(tmp[i]));
}
Console.WriteLine(solution(number));
}
}
}
'Algorithm' 카테고리의 다른 글
백준 1149 (0) | 2023.08.20 |
---|---|
백준 11866 (0) | 2023.08.19 |
백준 2798 (0) | 2023.08.18 |
백준 2839 (0) | 2023.08.18 |
시작한 계기 (0) | 2023.08.18 |
댓글()