题解 | #坐标移动#

坐标移动

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

}

全部评论

相关推荐

coffrar:全都是已读😅沟通一千五百多个了
点赞 评论 收藏
分享
黑皮白袜臭脚体育生:简历条例统一按使用了什么技术实现了什么功能解决了问题或提升了什么性能指标来写会好些,如使用布隆过滤器实现了判断短链接是否存在,大大提升了查询速度
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务