题解 | #坐标移动#

坐标移动

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

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
    while(line = await readline()){
        const list = line.split(';')
        const arr = []
        var x =0;
        var y =0;
        for(let i=0;i<list.length;i++) {
            const word = list[i].split('')[0]
            if(word !== 'A' && word !== 'S' &&word !=='W' && word !== 'D') {
                list.splice(i,1)
               
            }
            else {
                let num = parseInt(list[i].split('').splice(1).join(''))
                if(word=='A') {
                    x = x-num
                }else if(word == 'S') {
                    y = y-num
                }else if(word == 'W') {
                    y=y+num
                } else {
                    x = x+num
                }
            }

  

        }
        console.log([x,y].join(','))
 
    }
}()

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务