Skip to content

Instantly share code, notes, and snippets.

@dalcon10028
Created January 13, 2020 06:43
Show Gist options
  • Select an option

  • Save dalcon10028/c2734fcc3bd2a9ddbb9375b137f7eeea to your computer and use it in GitHub Desktop.

Select an option

Save dalcon10028/c2734fcc3bd2a9ddbb9375b137f7eeea to your computer and use it in GitHub Desktop.
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String exp = sc.next();
sc.close();
String []str = exp.split("-"); // '-' 기호 기준으로 배열에 담기
// 처음 '-'전까지 모두 더하기
String []tmp = str[0].split("\\+");
int first=0;
for (String t : tmp)
first += Integer.parseInt(t);
// 처음 '-' 이후 숫자 더하기
int sum = 0;
for(int i=1; i<str.length; i++){
String []temp = str[i].split("\\+");
for (String t : temp)
sum += Integer.parseInt(t);
}
System.out.println(first-sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment