#坐标移动#一般解题思路
坐标移动
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);
// 注意 hasNext 和 hasNextLine 的区别
int x = 0;
int y = 0;
String [] strs = in.nextLine().split(";");
for( int i = 0;i < strs.length ;i ++){
String str = strs[i];
if(str != null && str.length() > 1){
String tmpstr = str.substring(1);
Integer tmp;
try{
tmp = Integer.parseInt(tmpstr);
}catch (Exception e){
tmp = null;
}
if(tmp != null ){
if(str.startsWith("A")){
x -= tmp;
}else if(str.startsWith("D")){
x += tmp;
}else if(str.startsWith("W")){
y += tmp;
}else if(str.startsWith("S")){
y -= tmp;
}
}
}
}
System.out.println(x + "," + y);
}
}
SHEIN希音公司福利 356人发布
查看4道真题和解析

