题解 | #坐标移动#

坐标移动

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

import java.io.; import java.util.;

public class Main{

public static void main(String[] args) throws Exception{
    BufferedReader bf  = new BufferedReader(new InputStreamReader(System.in));
    String str = bf.readLine();
    String [] arr = str.split(";");
    int h = 0;
    int v = 0;
    for(int i = 0; i< arr.length; i++){
        String x = arr[i];
        int num =0;
        try{
            num = Integer.parseInt(x.substring(1));
        }catch(Exception e){
            continue;
        }
        String calc = x.substring(0,1);
        if("A".equals(calc)){
            h-=num;
        }else if("S".equals(calc)){
            v-=num;
        }else if("W".equals(calc)){
            v+=num;
        }else if("D".equals(calc)){
            h+=num;
        }          
    }
    System.out.println(h+","+v);
}

}

全部评论

相关推荐

不愿透露姓名的神秘牛友
今天 12:02
点赞 评论 收藏
分享
06-23 11:28
门头沟学院 Java
牛客91966197...:也有可能是点拒绝的时候自动弹的话术
点赞 评论 收藏
分享
北漂的牛马人:211佬,包进的,可能是系统问题
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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