解法

坐标移动

http://www.nowcoder.com/questionTerminal/119bcca3befb405fbe58abe9c532eb29

import java.util.*;
class Point{
        public int x;
        public int y;
        public Point(int x,int y){
            this.x=x;
            this.y=y;
        }
    }
public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String[] arr = scan.next().split("\\;+");
        Point now=new Point(0,0);
        for(int i=0;i<arr.length;i++){
            if(isValid(arr[i])){
                char ch=arr[i].charAt(0);
                int num=Integer.valueOf(arr[i].substring(1));
                if(ch=='A'){
                    now.x-=num;
                }else if(ch=='D'){
                    now.x+=num;
                }else if(ch=='W'){
                    now.y+=num;
                }else if(ch=='S'){
                    now.y-=num;
                }
            }
        }
        System.out.println(now.x+","+now.y);
    }
    public static boolean isValid(String str){
        char ch=str.charAt(0);
        if(ch=='A'||ch=='D'||ch=='W'||ch=='S'){
            str=str.substring(1);
            for(int i=0;i<str.length();i++){
                if(!Character.isDigit(str.charAt(i))){
                    return false;
                }
            }
            return true;
        }else{
            return false;
        }
    }
}
全部评论

相关推荐

07-15 12:24
重庆大学 运营
坏消息:和好工作擦肩而过
给点吧求求了:怎么可能因为差几秒,估计就是简历更好看婉拒了
点赞 评论 收藏
分享
06-17 00:26
门头沟学院 Java
程序员小白条:建议换下项目,智能 AI 旅游推荐平台:https://github.com/luoye6/vue3_tourism_frontend 智能 AI 校园二手交易平台:https://github.com/luoye6/vue3_trade_frontend GPT 智能图书馆:https://github.com/luoye6/Vue_BookManageSystem 选项目要选自己能掌握的,然后最好能自己拓展的,分布式这种尽量别去写,不然你只能背八股文了,另外实习的话要多投,尤其是学历不利的情况下,多找几段实习,最好公司title大一点的
无实习如何秋招上岸
点赞 评论 收藏
分享
06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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