题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
int x=0;
int y=0;
Scanner in=new Scanner(System.in);
String pro=in.next();
String[] ans=new String[pro.length()];
String test="";
int count=0;
for (int i = 0; i <pro.length() ; i++) {
if(pro.charAt(i)==';'){
ans[count++]=test;
test="";
}
else {
test=test+pro.charAt(i);
}
}
ans[count++]=test;
for (int i = 0; i < count; i++) {
if(ans[i].length()==3){
if((ans[i].charAt(1)>=48&&ans[i].charAt(1)<=57)&&(ans[i].charAt(2)>=48&&ans[i].charAt(2)<=57)&&(ans[i].charAt(0)>=65&&ans[i].charAt(0)<=97)){
if(ans[i].charAt(0)=='A'){
String c1="";
c1=c1+ans[i].charAt(1)+ans[i].charAt(2);
x=x-Integer.parseInt(c1);
}
else if(ans[i].charAt(0)=='W'){
String c2="";
c2=c2+ans[i].charAt(1)+ans[i].charAt(2);
y=y+Integer.parseInt(c2);
}
else if(ans[i].charAt(0)=='D'){
String c3="";
c3=c3+ans[i].charAt(1)+ans[i].charAt(2);
x=x+Integer.parseInt(c3);
}
else if(ans[i].charAt(0)=='S'){
String c4="";
c4=c4+ans[i].charAt(1)+ans[i].charAt(2);
y=y-Integer.parseInt(c4);
}
}
}
if(ans[i].length()==2){
if((ans[i].charAt(1)>=48&&ans[i].charAt(1)<=57)&&(ans[i].charAt(0)>=65&&ans[i].charAt(0)<=97)){
if(ans[i].charAt(0)=='A'){
String c1="";
c1=c1+ans[i].charAt(1);
x=x-Integer.parseInt(c1);
}
else if(ans[i].charAt(0)=='W'){
String c2="";
c2=c2+ans[i].charAt(1);
y=y+Integer.parseInt(c2);
}
else if(ans[i].charAt(0)=='D'){
String c3="";
c3=c3+ans[i].charAt(1);
x=x+Integer.parseInt(c3);
}
else if(ans[i].charAt(0)=='S'){
String c4="";
c4=c4+ans[i].charAt(1);
y=y-Integer.parseInt(c4);
}
}
}
}
System.out.println(x+","+y);
}
}
