题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String[] temp=sc.nextLine().split(";"); int x=0; int y=0; for(String s:temp){ if(s.length()==0 || s.length()==1 || s.length()>3){ continue; } switch (s.charAt(0)){ case 'A': { int num = 0; int fla =0; for(int i=1; i<s.length();i++){ if(s.charAt(i) > '9' || s.charAt(i) < 0){ fla = 1; break; } num = num*10 + (s.charAt(i)-'0'); } if(fla == 0){ x -= num; } break; } case 'D': { int num = 0; int fla =0; for(int i=1; i<s.length();i++){ if(s.charAt(i) > '9' || s.charAt(i) < 0){ fla = 1; break; } num = num*10 + (s.charAt(i)-'0'); } if(fla == 0){ x += num; } break; } case 'W': { int num = 0; int fla =0; for(int i=1; i<s.length();i++){ if(s.charAt(i) > '9' || s.charAt(i) < 0){ fla = 1; break; } num = num*10 + (s.charAt(i)-'0'); } if(fla == 0){ y += num; } break; } case 'S': { int num = 0; int fla =0; for(int i=1; i<s.length();i++){ if(s.charAt(i) > '9' || s.charAt(i) < 0){ fla = 1; break; } num = num*10 + (s.charAt(i)-'0'); } if(fla == 0){ y -= num; } break; } default: break; } } System.out.println(x+","+y); } }
#哈啰出行招聘#