20250721 baekjoon
This commit is contained in:
parent
7b30cf3045
commit
c4ecc66191
34
code_study/Baekjoon/java/_1541.java
Normal file
34
code_study/Baekjoon/java/_1541.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
code_study/Baekjoon/python/1541.py
Normal file
8
code_study/Baekjoon/python/1541.py
Normal 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:]))
|
||||||
Loading…
x
Reference in New Issue
Block a user