题解 | #坐标移动#

坐标移动

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);
        int x = 0;
        int y = 0;
        // 注意 hasNext 和 hasNextLine 的区别
        //while (in.hasNextInt()) { // 注意 while 处理多个 case
        String str = in.next();
        String[] atrAry = str.split(";");
        for (int i = 0; i < atrAry.length; i++) {
            String temp = atrAry[i];
            StringBuilder stringBuilder = new StringBuilder(temp);
            String s2 = stringBuilder.reverse().toString();
            if (temp.length() < 4 && temp.length() >= 2) {
                if (!s2.startsWith("A") && !s2.startsWith("S") && !s2.startsWith("W") &&
                        !s2.startsWith("D")) {

                    if (temp.startsWith("A")) {
                        x = x - Integer.valueOf(temp.substring(1, temp.length()));
                    } else if (temp.startsWith("W")) {
                        y = y + Integer.valueOf(temp.substring(1, temp.length()));
                    } else if (temp.startsWith("S")) {
                        y = y - Integer.valueOf(temp.substring(1, temp.length()));
                    } else if (temp.startsWith("D")) {
                        x = x + Integer.valueOf(temp.substring(1, temp.length()));
                    }
                }
            }
        }
        System.out.println(x + "," + y);
    }
}

全部评论

相关推荐

06-12 17:46
门头沟学院 Java
运营你豪哥:来说重点: ​1.项目前置,时间倒序。​​ 2.​项目描述强化结果与量化效果(STAR原则里的R)。​​ ​3.个人技能精炼,明确掌握程度,突出核心。​​ ​4.增加强有力开头的个人总结部分。​​ 5.​优化教育背景(成绩排名)、合并奖项与活动。​​
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
测试糕手手:社会第一课,随便吹牛逼,直接说四个月,别老实。老实人只会被欺负
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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