문제 설명


문제 분석


슈도코드

구현
public class 최솟값을_만드는_괄호_1541 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int result = 0;
String s = scan.nextLine();
String[] str = s.split("-");
for (int i = 0; i < str.length; i++) {
int temp = mySum(str[i]);
if (i == 0) {
result += temp; // 가장 앞에 있는 값만 더하기
} else {
result -= temp; // 뒷부분은 더한 값들을 뺌
}
}
System.out.println(result);
}
// 나뉜 그룹의 더하기 연산 수행
private static int mySum(String s) {
int sum = 0;
String[] temp = s.split("[+]");
for (int i = 0; i < temp.length; i++) {
sum += Integer.parseInt(temp[i]);
}
return sum;
}
}