#include <stdio.h>
#include <iostream>
#include <stack>
#include <string>
int main()
{
std::ios::sync_with_stdio(0);
std::cin.tie(0);
while (true)
{
std::string str_buf;
getline(std::cin, str_buf);
if (str_buf == ".") break;
std::stack<char> s;
bool isValid = true;
for (int i = 0; str_buf[i] != '\0'; ++i)
{
char c = str_buf[i];
if (c == '(' || c == '[') s.push(c);
else if (c == ')') {
if (s.empty() || s.top() != '(') {
isValid = false;
break;
}
s.pop();
}
else if (c == ']') {
if (s.empty() || s.top() != '[') {
isValid = false;
break;
}
s.pop();
}
}
if (!s.empty()) isValid = false;
if (isValid) std::cout << "yes\n";
else std::cout << "no\n";
}
}
// 유사 문제
// 백준 10799번: 쇠막대기
// 백준 2504번: 괄호의 값
출처: https://www.acmicpc.net/problem/4949
4949번: 균형잡힌 세상
각 문자열은 마지막 글자를 제외하고 영문 알파벳, 공백, 소괄호("( )"), 대괄호("[ ]")로 이루어져 있으며, 온점(".")으로 끝나고, 길이는 100글자보다 작거나 같다. 입력의 종료조건으로 맨 마지막에
www.acmicpc.net
'코테 & 알고리즘 > 백준' 카테고리의 다른 글
[백준] 실버1. 미로 탐색(2178번) (0) | 2023.10.15 |
---|---|
[백준] 실버1. 그림(1926번) (0) | 2023.10.15 |
[백준] 실버5. 줄세우기(10431번) (0) | 2023.10.06 |
[백준] 브론즈2. 럭키 스트레이트(18406번) (1) | 2023.10.05 |
[백준] 브론즈5. 그대로 출력하기(11718번) (0) | 2023.10.05 |