题解 | #坐标移动#

坐标移动

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);
}

}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-16 18:05
何尝不是一种学历歧视呢
码农索隆:楼主明确拒绝,并说明拒绝原因了,这hr倒是挺忠心护主的
点赞 评论 收藏
分享
头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
07-17 11:27
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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