题解 | #坐标移动#

坐标移动

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);
    String  str=in.nextLine();
    String[] strs=str.split(";");
    int[] x=new int[2];
    for(String a:strs){
        if(!a.isEmpty()){
                if(a.matches("[AWSD][0-9]*")){
                    int y=Integer.parseInt(String.valueOf(a.substring(1)));
                switch(a.substring(0,1)){
                    case "A":x[0]-=y;break;
                    case "S":x[1]-=y;break;
                    case "W":x[1]+=y;break;
                    case "D":x[0]+=y;break;                  
                }
                }
        }
    }
    System.out.println(x[0]+","+x[1]);
    }
}

全部评论

相关推荐

震撼沃玛一整年:查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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