namespace SongE
{
public class Program2
{
static void Main(string[] args)
{
using var input = new System.IO.StreamReader(Console.OpenStandardInput());
//int intInput() => int.Parse(input.ReadLine());
//int[] intsInput() => Array.ConvertAll(input.ReadLine().Split(), s => int.Parse(s));
string s;
while ((s = input.ReadLine()) != ".")
{
IsBalanced(s.ToCharArray());
}
}
static void IsBalanced(char[] chars)
{
using var output = new System.IO.StreamWriter(Console.OpenStandardOutput());
Stack<char> stack = new Stack<char>(chars);
Stack<char> pStack = new();
bool isBalanced = true;
char before = ' ';
while (stack.TryPop(out char c))
{
if (char.IsWhiteSpace(c) || c == '.' || char.IsLetter(c))
{
before = c;
continue;
}
else //[()]
{
// 문자균형
if (stack.TryPeek(out char t))
{
if (char.IsLetter(t) && char.IsLetter(before))
{
isBalanced = false;
break;
}
}
before = c;
if (c == ']' || c == ')')
{
pStack.Push(c); continue;
}
else
{
if (pStack.TryPop(out char p))
{
if (c == '[' && p == ']' || c == '(' && p == ')')
{
continue;
}
}
isBalanced = false;
break;
}
}
}
if(pStack.Count > 0) isBalanced = false;
output.WriteLine(isBalanced ? "yes" : "no");
}
}
}
알고보니까 단어가 잘리는건 상관이 없었다
namespace SongE
{
public class Program2
{
static void Main(string[] args)
{
using var input = new System.IO.StreamReader(Console.OpenStandardInput());
//int intInput() => int.Parse(input.ReadLine());
//int[] intsInput() => Array.ConvertAll(input.ReadLine().Split(), s => int.Parse(s));
string s;
while ((s = input.ReadLine()) != ".")
{
IsBalanced(s.ToCharArray());
}
}
static void IsBalanced(char[] chars)
{
using var output = new System.IO.StreamWriter(Console.OpenStandardOutput());
Stack<char> stack = new Stack<char>(chars);
Stack<char> pStack = new();
bool isBalanced = true;
while (stack.TryPop(out char c))
{
if (char.IsWhiteSpace(c) || c == '.' || char.IsLetter(c))
{
continue;
}
else //[()]
{
if (c == ']' || c == ')')
{
pStack.Push(c); continue;
}
else
{
if (pStack.TryPop(out char p))
{
if (c == '[' && p == ']' || c == '(' && p == ')')
{
continue;
}
}
isBalanced = false;
break;
}
}
}
if (pStack.Count > 0) isBalanced = false;
output.WriteLine(isBalanced ? "yes" : "no");
}
}
}
namespace SongE
{
public class Program2
{
static void Main(string[] args)
{
using var input = new System.IO.StreamReader(Console.OpenStandardInput());
using var output = new System.IO.StreamWriter(Console.OpenStandardOutput());
//int intInput() => int.Parse(input.ReadLine());
//int[] intsInput() => Array.ConvertAll(input.ReadLine().Split(), s => int.Parse(s));
string s;
while ((s = input.ReadLine()) != ".")
{
output.WriteLine(IsBalanced(s.ToCharArray()) ? "yes" : "no");
}
}
static bool IsBalanced(char[] chars)
{
Stack<char> stack = new();
foreach(char c in chars)
{
if (char.IsLetter(c) || c == ' ' || c == '.')
continue;
else
{
if(c == '[' || c == '(')
stack.Push(c);
else
{
if (stack.TryPop(out char t))
{
if (t == '[' && c == ']' || t == '(' && c == ')')
continue;
else
{
return false;
}
}
else
return false;
}
}
}
return stack.Count > 0 ? false : true;
}
}
}