题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String line = in.nextLine();
String[] lines = line.split(";");
int a =0,b=0;
for(int i=0;i<lines.length;i++){
String ops = lines[i];
if(ops == null || ops.equals("")){
continue;
}
char option = ops.charAt(0);
String nums = ops.substring(1);
int step=0;
try{
step = Integer.parseInt(nums);
}catch(NumberFormatException e){
continue;
}
switch(option){
case 'A':
a-=step;
break;
case 'D':
a+=step;
break;
case 'W':
b+=step;
break;
case 'S':
b-=step;
break;
}
}
System.out.print(a+","+b);
}
}
