Skip to content

Commit 3989d10

Browse files
committed
[D4] Title: [S/W 문제해결 기본] 9일차 - 사칙연산 유효성 검사, Time: 129 ms, Memory: 34,688 KB -BaekjoonHub
1 parent 056ab2b commit 3989d10

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# [D4] [S/W 문제해결 기본] 9일차 - 사칙연산 유효성 검사 - 1233
2+
3+
[문제 링크](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV141176AIwCFAYD)
4+
5+
### 성능 요약
6+
7+
메모리: 34,688 KB, 시간: 129 ms, 코드길이: 1,534 Bytes
8+
9+
### 제출 일자
10+
11+
2026-09-02 17:11
12+
13+
14+
15+
> 출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import java.util.*;
2+
import java.io.FileInputStream;
3+
4+
5+
class Solution
6+
{
7+
static class Node{
8+
private int idx;
9+
private char me;
10+
private int leftNode = -1;
11+
private int rightNode = -1;
12+
13+
Node(int idx, char me, int left, int right){
14+
this.idx = idx;
15+
this.me = me;
16+
this.leftNode = left;
17+
this.rightNode = right;
18+
}
19+
20+
}
21+
22+
public static void main(String args[]) throws Exception
23+
{
24+
25+
Scanner sc = new Scanner(System.in);
26+
27+
28+
for(int test_case = 1; test_case <= 10; test_case++)
29+
{
30+
31+
int N = Integer.parseInt(sc.nextLine().trim());
32+
33+
ArrayList<Node> list = new ArrayList<>();
34+
list.add(null);
35+
36+
for(int i=1; i<=N; i++) {
37+
String[] tokens = sc.nextLine().trim().split(" ");
38+
int idx = Integer.parseInt(tokens[0]);
39+
char me = tokens[1].charAt(0);
40+
int left = tokens.length > 2 ? Integer.parseInt(tokens[2]) : -1;
41+
int right = tokens.length > 3 ? Integer.parseInt(tokens[3]) : -1;
42+
43+
list.add(new Node(idx, me, left, right));
44+
45+
}
46+
47+
System.out.println("#" + test_case + " " + isAvailable(list, N));
48+
49+
}
50+
51+
sc.close();
52+
}
53+
54+
public static int isAvailable(ArrayList<Node> list, int N) {
55+
for (int i = 1; i <= N; i++) {
56+
Node node = list.get(i);
57+
58+
boolean hasChildren = (node.leftNode != -1 || node.rightNode != -1);
59+
60+
if (hasChildren) {
61+
62+
if (node.me != '+' && node.me != '-' && node.me != '*' && node.me != '/') {
63+
return 0;
64+
}
65+
} else {
66+
67+
if (node.me < '0' || node.me > '9') {
68+
return 0;
69+
}
70+
}
71+
}
72+
73+
return 1;
74+
}
75+
76+
77+
}

0 commit comments

Comments
 (0)