(알고스팟) 괄호닫기.

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();
}

댓글

이 블로그의 인기 게시물

(네트워크)폴링방식 vs 롱 폴링방식

(ElasticSearch) 결과에서 순서 정렬

(18장) WebSocekt과 STOMP를 사용하여 메시징하기