-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString_9.java
More file actions
65 lines (54 loc) · 1.12 KB
/
Copy pathString_9.java
File metadata and controls
65 lines (54 loc) · 1.12 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
63
64
65
package HuaweiCoding;
import java.util.Scanner;
/*
*
*/
public class String_9 {
public static int x=0;
public static int y=0;
public static void moveLocation(String location) {
if(location.length()==0) {
return;
}
char[] fields = location.toCharArray();
char firstChar = fields[0];
if(firstChar!='A' && firstChar!='S' &&
firstChar!='D' && firstChar!='W' ) {
return;
}
for(int i=1;i<fields.length;i++) {
if(!(fields[i]>='0' && fields[i]<='9')) {
return;
}
}
int counts=0;
for(int i=1;i<fields.length;i++) {
counts*=10;
counts+=Integer.parseInt(fields[i]+"");
}
if(firstChar=='A') {
x-=counts;
}
if(firstChar=='S') {
y-=counts;
}
if(firstChar=='D') {
x+=counts;
}
if(firstChar=='W') {
y+=counts;
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) {
String[] inputLine = sc.nextLine().split(";");
for (String inputStr : inputLine) {
moveLocation(inputStr);
}
System.out.println(x+","+y);
x=0;
y=0;
}
}
}