-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocation.java
More file actions
41 lines (37 loc) · 1.06 KB
/
Location.java
File metadata and controls
41 lines (37 loc) · 1.06 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
package com.hw;
import java.util.Scanner;
/**
* @author: yhl
* @DateTime: 2020/5/14 21:39
* @Description:
*/
public class Location {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
String location = in.nextLine();
String[] locations = location.split(";");
int a = 0;
int b = 0;
for (String l : locations) {
try {
int num = Integer.parseInt(l.substring(1));
if (l.charAt(0) == 'A') {
a -= num;
}
if (l.charAt(0) == 'D') {
a += num;
}
if (l.charAt(0) == 'W') {
b += num;
}
if (l.charAt(0) == 'S') {
b -= num;
}
} catch (Exception ignored) {
}
}
System.out.println(a + "," + b);
}
}
}