forked from damaohongtu/JavaInterview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZoom.java
More file actions
62 lines (57 loc) · 1.58 KB
/
Zoom.java
File metadata and controls
62 lines (57 loc) · 1.58 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package BiShi;
import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
/**
* @Author MaoTian
* @Classname Zoom
* @Description TODO
* @Date 下午2:28 2019/8/17
* @Version 1.0
* @Created by mao<[email protected]>
*/
public class Zoom {
public static void main(String[] args)throws Exception {
Scanner sc =new Scanner(new File("/home/mao/workspace/java/src/BiShi/test"));
//Scanner sc =new Scanner(System.in);
while(sc.hasNext()){
String s=sc.next();
char[] arr=s.toCharArray();
int count=0;
int num=0;
ArrayList<Integer> res=new ArrayList<>();
for(int i=0;i<arr.length;i++){
if (Character.isDigit(arr[i])){
num=num*10+arr[i]-'0';
continue;
}
if (Character.isLetter(arr[i])||arr[i]=='.'){
if(count%2!=0){
num=0-num;
}
res.add(num);
num=0;
count=0;
continue;
}
else if (arr[i]=='-'){
count++;
continue;
}
}
if(count%2!=0){
num=0-num;
}
res.add(num);
int ans=0;
for (Integer i:res){
ans+=i;
}
if(res.isEmpty()){
System.out.println(0);
}else{
System.out.println(ans);
}
}
}
}