Skip to content

Commit

Permalink
Merge pull request #9 from AlgoLeadMe/3-g0rnn
Browse files Browse the repository at this point in the history
3-g0rnn
  • Loading branch information
g0rnn authored Oct 29, 2024
2 parents 32f04c7 + 89e3081 commit 0f64fba
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions g0rnn/๋ฌธ์ž์—ด/3-g0rnn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
public static void main(String[] args) throws IOException {
String expression;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
expression = br.readLine();

int sum = Integer.MAX_VALUE;
String[] splitNumbersByMinus = expression.split("-");

for (int i = 0; i < splitNumbersByMinus.length; i++) {
String[] parts = splitNumbersByMinus[i].split("\\+");
int partSum = 0;

for (int j = 0; j < parts.length; j++)
partSum += Integer.parseInt(parts[j]);

if(sum == Integer.MAX_VALUE) sum = partSum;
else sum -= partSum;
}

System.out.println(sum);
}
}

0 comments on commit 0f64fba

Please sign in to comment.