题解 | #坐标移动#

坐标移动

https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] split = in.nextLine().split(";");
        int a = 0,b = 0;
        for (String string : split) {
            try {
                switch (string.substring(0, 1)) {
                    case "A":
                        a -= Integer.parseInt(string.substring(1));
                        break;
                    case "D":
                        a += Integer.parseInt(string.substring(1));
                        break;
                    case "S":
                        b -= Integer.parseInt(string.substring(1));
                        break;
                    case "W":
                        b += Integer.parseInt(string.substring(1));
                        break;
                }
            } catch (Exception ignored) {

            }
        }
        System.out.println(a + "," + b);
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务