File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 32412 KB, 시간: 40 ms
7+ 메모리: 14376 KB, 시간: 104 ms
88
99### 분류
1010
11- 자료 구조, 구현 , 스택
11+ 구현, 자료 구조, 스택
1212
1313### 제출 일자
1414
15- 2025년 4월 2일 20:00:38
15+ 2025년 10월 24일 10:47:23
1616
1717### 문제 설명
1818
Original file line number Diff line number Diff line change 1+ import java .io .BufferedReader ;
2+ import java .io .IOException ;
3+ import java .io .InputStreamReader ;
4+ import java .util .*;
5+
6+ public class Main {
7+
8+ public static void main (String [] args ) throws IOException {
9+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
10+ String line = br .readLine ();
11+
12+ Stack <Character > stack = new Stack <>();
13+ int res = 0 ;
14+ int value = 1 ;
15+
16+ for (int i = 0 ; i < line .length (); i ++) {
17+ if (line .charAt (i ) == '(' ) {
18+ stack .push (line .charAt (i ));
19+ value *= 2 ;
20+ } else if (line .charAt (i ) == '[' ) {
21+ stack .push (line .charAt (i ));
22+ value *= 3 ;
23+ } else if (line .charAt (i ) == ')' ) {
24+ if (stack .isEmpty () || stack .peek () != '(' ) {
25+ res = 0 ;
26+ break ;
27+ } else if (line .charAt (i - 1 ) == '(' ) {
28+ res += value ;
29+ }
30+ stack .pop ();
31+ value /= 2 ;
32+ } else if (line .charAt (i ) == ']' ) {
33+ if (stack .isEmpty () || stack .peek () != '[' ) {
34+ res = 0 ;
35+ break ;
36+ } else if (line .charAt (i - 1 ) == '[' ) {
37+ res += value ;
38+ }
39+
40+ stack .pop ();
41+ value /= 3 ;
42+ }
43+ }
44+
45+ if (!stack .isEmpty ()) System .out .println (0 );
46+ else System .out .println (res );
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments