[BOJ] 1874 스택 수열
Algorithm 2023. 1. 16. 02:21반응형
https://www.acmicpc.net/problem/1874
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace BOJ
{
class Program
{
static void Main()
{
StreamReader sr = new StreamReader(Console.OpenStandardInput());
StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
StringBuilder sb = new StringBuilder();
List<int> list = new List<int>();
int number = 0;
Stack<int> stack = new Stack<int>();
int a = int.Parse(sr.ReadLine());
for (int i = 0; i < a; i++)
{
list.Add(int.Parse(sr.ReadLine()));
}
for (int i = 1; i <= a; i++)
{
stack.Push(i);
sb.Append("+" + "\n");
while (stack.Count != 0 && stack.Peek() == list[number])
{
stack.Pop();
sb.Append("-" + "\n");
number++;
}
}
if (stack.Count == 0)
{
sw.WriteLine(sb);
}
else
{
sw.WriteLine("NO");
}
sr.Close();
sw.Flush();
sw.Close();
}
}
}
반응형
'Algorithm' 카테고리의 다른 글
BST (Binary Search Tree) (0) | 2023.01.16 |
---|---|
LCRS Tree (0) | 2023.01.16 |
[BOJ] 9093 단어 뒤집기 (0) | 2023.01.16 |
[BOJ] 1439 뒤집기 (0) | 2023.01.16 |
[BOJ] 5585 거스름돈 (0) | 2023.01.16 |