using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
// Use this for initialization
public string a = "{[{}{}]}[()]",
b = "{{}{}}",
c = "[]{}()",
d = "{()}[)",
e = "{(})";
void Start () {
print(IsBracketMatch(a));
print(IsBracketMatch(b));
print(IsBracketMatch(c));
print(IsBracketMatch(d));
print(IsBracketMatch(e));
}
// Update is called once per frame
public bool IsBracketMatch(string str)
{
// c = "[]{}()",
Stack<char> stack = new Stack<char>();
for (int i = 0; i < str.Length; i++)
{
switch (str[i])
{
case '{':
case '[':
case '(':
stack.Push(str[i]);
break;
case '}':
if (stack.Count > 0 && stack.Pop() == '{')
break;
else
return false;
case ']':
if (stack.Count > 0 && stack.Pop() == '[')
break;
else
return false;
case ')':
if (stack.Count > 0 && stack.Pop() == '(')
break;
else
return false;
default:
return false;
}
}
return stack.Count == 0;
}
}