题解 | #坐标移动#

坐标移动

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

var str = readline().split(';');
var x = 0;
var y = 0;
for (let item of str){
    const startWord = item.substring(0,1);
    const n = Number(item.substr(1));
    if(item.length <= 3 && item.length > 1 && !isNaN(n)){
        if(startWord === 'A'){
            x -= n;
        } else if(startWord === 'D'){
            x += n;
        } else if(startWord === 'W'){
            y += n;
        } else if(startWord === 'S'){
            y -=n;
        }
    }
}
console.log(x+','+y)
全部评论

相关推荐

瑞雪兆丰年_:可以贴个超级大的校徽,以防HR眼拙
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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