题解 | #坐标移动#

坐标移动

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

import java.io.*;
import java.util.*;
public class Main{
    public static boolean isNum(char c){
        if(c>='0'&&c<='9') return true;
        else{
            return false;
        }
    }
    public static void main(String[] args){
        Scanner sc = new Scanner (System.in);
        String input = sc.nextLine();
        String[] str = input.split(";");
        int x=0,y=0;
        for(int i = 0;i<str.length;i++){
            String locstr = str[i];
            if(locstr.length()<=1 || locstr.length()>3) continue;
            char dir = locstr.charAt(0);
            String numstr = locstr.substring(1);
            int res=0,val=0;
            if ((numstr.length()==1 && isNum(numstr.charAt(0)))||(numstr.length()==2 &&isNum(numstr.charAt(0))&&isNum(numstr.charAt(1)))){
                val = Integer.parseInt(numstr); 
                switch(dir){
                    case 'A':
                        x -= val;
                        break;
                     case 'S':
                        y -= val;
                        break;
                     case 'W':
                        y += val;
                        break;
                     case 'D':
                        x += val;
                        break;
                     default:
                        x +=0;
                }
            }
        }
        System.out.println(x+","+y);
    }

}
全部评论

相关推荐

05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
粗心的熊熊求求off...:什么内容都没有还弄两页
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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