题解 | #坐标移动#java

坐标移动

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] str = reader.readLine().toUpperCase().split(";");
        int j = 0, x = 0, y = 0, num = 0;
        for (int i = 0; i < str.length; i++) {
            if (str[i].length() > 1 && str[i].length() < 4) {
                if (str[i].charAt(0) == 'A' || str[i].charAt(0) == 'S' || str[i].charAt(0) == 'D' || str[i].charAt(0) == 'W') {
                    if (Integer.valueOf(str[i].charAt(1)) > 47 && Integer.valueOf(str[i].charAt(1)) < 58) {
                        if (str[i].length() != 2) {
                            if (Integer.valueOf(str[i].charAt(2)) > 47 && Integer.valueOf(str[i].charAt(2)) < 58) {
                                num = Integer.parseInt(str[i].substring(1));
                                switch (str[i].charAt(0)) {
                                    case 'A':
                                        x = x - num;
                                        break;
                                    case 'D':
                                        x = x + num;
                                        break;
                                    case 'S':
                                        y = y - num;
                                        break;
                                    case 'W':
                                        y = y + num;
                                        break;
                                    default:
                                        break;
                                }
                            }
                        } else {
                            num = Integer.parseInt(str[i].substring(1));
                            switch (str[i].charAt(0)) {
                                case 'A':
                                    x = x - num;
                                    break;
                                case 'D':
                                    x = x + num;
                                    break;
                                case 'S':
                                    y = y - num;
                                    break;
                                case 'W':
                                    y = y + num;
                                    break;
                                default:
                                    break;
                            }
                        }
                    }

                }
            }

        }
        System.out.println(x + "," + y);
    }

}

全部评论

相关推荐

吐泡泡的咸鱼:我也工作了几年了,也陆陆续续面试过不少人,就简历来说,第一眼学历不太够,你只能靠你的实习或者论文或者项目经历,然后你没有论文,没有含金量高的比赛和奖项,只能看实习和项目,实习来说,你写的实习经历完全不清楚你想找什么工作?行研?数据分析?且写的太少了,再看项目,这些项目先不说上过大学读过研究生的都知道很水,然后对你想找的岗位有什么帮助呢?项目和实习也完全不匹配啊,你好像在努力将你所有的经历都放在简历里想表现你的优秀,但是对于你想找的岗位来说,有什么用呢?最后只能获得岗位不匹配的评价。所以你需要明白你想要找的岗位要求是什么,是做什么的,比如产品经理,然后再看你的经历里有什么匹配的上这个岗位,或者对这个岗位以及这个岗位所在的公司有价值,再写到你的简历上
点赞 评论 收藏
分享
流浪的神仙:无恶意,算法一般好像都得9硕才能干算法太卷啦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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