题解 | #坐标移动#

坐标移动

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);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String a = in.next();
            System.out.println(v(a));
        }
    }
    //A10;S20;W10;D30;X;A1A;B10A11;;A10;
    private static String v(String str) {
        int x = 0;
        int y = 0;
        String[] step = str.split(";");
        for (String s: step) {
            try {
                int value = Integer.parseInt(s.substring(1));
                if (value <=0) continue;

                if (s.startsWith("A")) {
                    x -= value;
                }
                if (s.startsWith("S")) {
                    y -= value;
                }
                if (s.startsWith("W")) {
                    y += value;
                }
                if (s.startsWith("D")) {
                    x += value;
                }
            } catch (Exception e) {

            }
        }
        return x + "," + y;
    }
}

全部评论

相关推荐

11-23 15:33
已编辑
门头沟学院 Java
CUTMR:换账号试试重启推荐算法,我换账号之后回复率还不错,约莫有个20%左右的消息回复率,前几页、主动招呼的HR也开始符合我期望薪资,此前的大号从招呼、回复、前几页的岗位薪资在涨幅30%+以上 用着用着聊着聊着就变成-20%,而且我开通会员之后直接0面试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务