시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 652 265 227 39.825%

문제

세계는 균형이 잘 잡혀있어야 한다. 양과 음, 빛과 어둠 그리고 왼쪽 괄호와 오른쪽 괄호처럼 말이다.

정민이의 임무는 어떤 문자열이 주어졌을 때, 괄호들의 균형이 잘 맞춰져 있는지 판단하는 프로그램을 짜는 것이다.

문자열에 포함되는 괄호는 소괄호("()") 와 대괄호("[]")로 2종류이고, 문자열이 균형을 이루는 조건은 아래와 같다.

  • 모든 왼쪽 소괄호("(")는 오른쪽 소괄호(")")와만 짝을 이룰 수 있다.
  • 모든 왼쪽 대괄호("[")는 오른쪽 대괄호("]")와만 짝을 이룰 수 있다.
  • 모든 오른쪽 괄호들은 자신과 짝을 이룰 수 있는 왼쪽 괄호가 존재한다.
  • 모든 괄호들의 짝은 1:1 매칭만 가능하다. 즉, 괄호 하나가 둘 이상의 괄호와 짝지어지지 않는다.
  • 짝을 이루는 두 괄호가 있을 때, 그 사이에 있는 문자열도 균형이 잡혀야 한다.

정민이를 도와 문자열이 주어졌을 때 균형잡힌 문자열인지 아닌지를 판단해보자.

입력

하나 또는 여러줄에 걸쳐서 문자열이 주어진다. 각 문자열은 영문 알파벳, 공백, 소괄호("( )") 대괄호("[ ]")등으로 이루어져 있으며, 길이는 100글자보다 작거나 같다.

입력의 종료조건으로 맨 마지막에 점 하나(".")가 들어온다.

출력

각 줄마다 해당 문자열이 균형을 이루고 있으면 "yes"를, 아니면 "no"를 출력한다.

예제 입력 1

So when I die (the [first] I will see in (heaven) is a score list).
[ first in ] ( first out ).
Half Moon tonight (At least it is better than no Moon at all].
A rope may form )( a trail in a maze.
Help( I[m being held prisoner in a fortune cookie factory)].
([ (([( [ ] ) ( ) (( ))] )) ]).
 .
.

예제 출력 1

yes
yes
no
no
no
yes
yes

힌트

7번째의 " ."와 같이 괄호가 하나도 없는 경우도 균형잡힌 문자열로 간주할 수 있다.

W3sicHJvYmxlbV9pZCI6IjQ5NDkiLCJ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3IgbW9yZSBsaW5lcywgZWFjaCBvZiB3aGljaCBiZWluZyBhIGRhdGFzZXQuIEEgZGF0YXNldCBpcyBhIHN0cmluZyB0aGF0IGNvbnNpc3RzIG9mIEVuZ2xpc2ggYWxwaGFiZXRzLCBzcGFjZSBjaGFyYWN0ZXJzLCBhbmQgdHdvIGtpbmRzIG9mIGJyYWNrZXRzLCByb3VuZCAoJmxkcXVvOyggKSZyZHF1bzspIGFuZCBzcXVhcmUgKCZsZHF1bztbIF0mcmRxdW87KSwgdGVybWluYXRlZCBieSBhIHBlcmlvZC4gWW91IGNhbiBhc3N1bWUgdGhhdCBldmVyeSBsaW5lIGhhcyAxMDAgY2hhcmFjdGVycyBvciBsZXNzLiBUaGUgbGluZSBmb3JtZWQgYnkgYSBzaW5nbGUgcGVyaW9kIGluZGljYXRlcyB0aGUgZW5kIG9mIHRoZSBpbnB1dCwgd2hpY2ggaXMgbm90IGEgZGF0YXNldC48XC9wPlxyXG4iLCJvdXRwdXQiOiI8cD5Gb3IgZWFjaCBkYXRhc2V0LCBvdXRwdXQgJmxkcXVvO3llcyZyZHF1bzsgaWYgdGhlIHN0cmluZyBpcyBiYWxhbmNlZCwgb3IgJmxkcXVvO25vJnJkcXVvOyBvdGhlcndpc2UsIGluIGEgbGluZS4gVGhlcmUgbWF5IG5vdCBiZSBhbnkgZXh0cmEgY2hhcmFjdGVycyBpbiB0aGUgb3V0cHV0LjxcL3A+XHJcbiIsImhpbnQiOiIiLCJvcmlnaW5hbCI6IjEiLCJwcm9ibGVtX2xhbmdfY29kZSI6Ilx1YzYwMVx1YzViNCJ9XQ==

출처

ACM-ICPC > Regionals > Asia > Japan > Domestic Contest > 2011 Domestic Contest B번

  • 잘못된 번역을 찾은 사람: jh05013
  • 문제를 번역한 사람: occidere