(알고스팟) 괄호닫기.

bool wellmatched(const string& formula)
{
const string opening("({["), closing(")}]");
stack<char> openStack;

for (int i = 0; i < formula.size(); ++i)
{
if (opening.find(formula[i]) != -1)
openStack.push(formula[i]);
else{
if (openStack.empty())return false;

if (opening.find(openStack.top()) != closing.find(formula[i]))
return false;
}
}
return openStack.empty();
}

댓글

이 블로그의 인기 게시물

(Garbage Collection) Old Area의 Concurrent Mark-sweep 알고리즘

(Pytorch) DataLoder 클래스

(데이터베이스) HAVING절과 WHERE 절의 차이