Algorithm/BOJ
[BOJ] 9012 괄호
Bueong_E
2023. 1. 24. 22:25
반응형
SMALL
풀이
using System;
using System.Collections.Generic;
namespace StudyforTomorrow
{
class App
{
//생성자
public App()
{
int n = int.Parse(Console.ReadLine());
List<string> lists = new List<string>();
while (lists.Count != n) { lists.Add(Console.ReadLine()); }
Stack<char> stack = new Stack<char>();
for (int i = 0; i < lists.Count; i++)
{
for (int j = 0; j < lists[i].Length; j++)
{
if (lists[i][j] == '(')
{
stack.Push(lists[i][j]);
}
else if (lists[i][j] == ')')
{
if (stack.Count == 0)
{
Console.WriteLine("No");
stack.Clear();
break;
}
stack.Pop();
}
if (lists[i].Length - 1 == j)
{
if (stack.Count == 0)
{
Console.WriteLine("Yes");
stack.Clear();
}
else
{
Console.WriteLine("No");
stack.Clear();
}
}
}
}
}
}
}
결과창
결과창 2
반응형
LIST