The Balance of the World
시간 제한 | 메모리 제한 | 제출 | 정답 | 맞은 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 128 MB | 938 | 365 | 319 | 39.776% |
The world should be finely balanced. Positive vs. negative, light vs. shadow, and left vs. right brackets. Your mission is to write a program that judges whether a string is balanced with respect to brackets so that we can observe the balance of the world.
A string that will be given to the program may have two kinds of brackets, round (“( )”) and square (“[ ]”). A string is balanced if and only if the following conditions hold.
- For every left round bracket (“(”), there is a corresponding right round bracket (“)”) in the following part of the string.
- For every left square bracket (“[”), there is a corresponding right square bracket (“]”) in the following part of the string.
- For every right bracket, there is a left bracket corresponding to it.
- Correspondences of brackets have to be one to one, that is, a single bracket never corresponds to two or more brackets.
- For every pair of corresponding left and right brackets, the substring between them is balanced.
입력
The input consists of one or more lines, each of which being a dataset. A dataset is a string that consists of English alphabets, space characters, and two kinds of brackets, round (“( )”) and square (“[ ]”), terminated by a period. You can assume that every line has 100 characters or less. The line formed by a single period indicates the end of the input, which is not a dataset.
출력
For each dataset, output “yes” if the string is balanced, or “no” otherwise, in a line. There may not be any extra characters in the output.
문제를 보고 왜 이 정답률이 39% 밖에 안되지? 라는 생각이 들었다.
스택의 개념을 활용하여 구현해 주면 된다.
'개발 > 알고리즘' 카테고리의 다른 글
python 속도 높이기 팁 (0) | 2019.03.18 |
---|---|
Codeforces Global Round 1 (A. Parity) (0) | 2019.02.08 |
2312 수 복원하기 (0) | 2019.01.24 |
1074번 Z (0) | 2019.01.15 |
11729 하노이 탑 이동순서 (0) | 2019.01.13 |