20250721 baekjoon

This commit is contained in:
songyc macbook 2025-07-21 22:27:18 +09:00
parent 7b30cf3045
commit c4ecc66191
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,34 @@
import java.util.*;
public class _1541 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] input = sc.nextLine().split("-");
sc.close();
ArrayList<Integer> num = new ArrayList<Integer>();
for(String s : input) {
int sum = 0;
if(s.contains("+")){
for(String n : s.split("\\+")){
sum += Integer.parseInt(n);
}
}
else {
sum += Integer.parseInt(s);
}
num.add(sum);
}
if(num.size()==1) {
System.out.println(num.get(0));
}
else {
int a = num.get(0);
int b = 0;
for(int i=1; i<num.size(); i++){
b += num.get(i);
}
System.out.println(a-b);
}
}
}

View File

@ -0,0 +1,8 @@
Str = input().split('-')
num = []
for s in Str:
total = 0
for n in map(int, s.split('+')):
total += n
num.append(total)
print(num[0] if len(num)==1 else num[0]-sum(num[1:]))