Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit 9f597c6

Browse files
committed
Q4949
1 parent 4a04455 commit 9f597c6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

thursday/week7/hagyoung99/Q4949.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package thursday.week7.hagyoung99;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
public class Q4949 {
6+
public String solution(String s){
7+
Stack<Character> stack = new Stack<>();
8+
for(char y : s.toCharArray()){
9+
if(y == '(') {
10+
stack.push(y);
11+
} else if(y=='[') {
12+
stack.push(y);
13+
} else if(y == ')' || y==']'){
14+
if(stack.empty()){
15+
return "no";
16+
} else {
17+
if(y==']') if(stack.peek() != '[') return "no";
18+
else stack.pop();
19+
else if(y==')') if(stack.peek() != '(') return "no";
20+
else stack.pop();
21+
}
22+
}
23+
}
24+
if(!stack.empty()) return "no";
25+
else return "yes";
26+
}
27+
public static void main(String[] args) throws IOException{
28+
Q4949 main = new Q4949();
29+
ArrayList<String> str = new ArrayList<>();
30+
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
31+
while(true){
32+
String s = in.readLine();
33+
if(s.equals(".")) break;
34+
str.add(main.solution(s));
35+
}
36+
37+
for(String x:str) System.out.println(x);
38+
}
39+
}

0 commit comments

Comments
 (0)