-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1541.java
More file actions
42 lines (36 loc) · 806 Bytes
/
P1541.java
File metadata and controls
42 lines (36 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package BOJ;
import java.io.*;
public class P1541 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int[] value = new int[line.length()];
int[] minus = new int[line.length()];
int index = 0;
int temp = 0;
for(int i=0;i<line.length();i++){
if(line.charAt(i)=='-' || line.charAt(i)=='+'){
temp = 0;
index++;
if(line.charAt(i)=='-'){
minus[index] = -1;
}
}
else{
temp = temp*10 + line.charAt(i)-'0';
value[index] = temp;
}
}
int ans = 0;
boolean state = false;
for(int i=0;i<=index;i++){
if(minus[i]==-1)
state = true;
if(state)
ans -= value[i];
else
ans += value[i];
}
System.out.println(ans);
}
}