
-Code
import java.io.*;
import java.util.*;
public class BOJ34998 {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
for (int i = 0; i < t; i++) {
int addCnt = Integer.parseInt(br.readLine());
String[] calc = br.readLine().split(" ");
int total = 0;
boolean isMany = false;
for (String str : calc) {
// +는 넘어감
if (str.equals("+")) {
continue;
}
// !이 하나라도 나오면 초과이므로 flag 변경 후 탈출
if (str.equals("!")) {
isMany = true;
break;
}
total += Integer.parseInt(str);
}
// 9보다 크면 flag 변경
if (total > 9) isMany = true;
System.out.println(isMany ? "!" : total);
}
}
}'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [백준/Java] 2346번 풍선 터뜨리기 (0) | 2025.12.28 |
|---|---|
| [백준/Java] 4779번 칸토어 집합 (0) | 2025.12.28 |
| [백준/Java] 24060번 알고리즘 수업 - 병합 정렬 1 (1) | 2025.12.27 |
| [백준/Java] 25501번 재귀의 귀재 (0) | 2025.12.27 |
| [백준/Java] 10870번 피보나치 수 5 (0) | 2025.12.27 |