题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
let line = readline()
let arr = line.split(';') //分割字符串位数组
let reg = /^(A|S|W|D){1}[0-9]{1,2}$/
let newarr = arr.filter(function(item){ //过滤数组
return reg.test(item)
})
let x = 0
let y = 0
newarr.forEach(function(item){ //坐标变换
let dir = item.charAt(0)
let val = Number(item.slice(1))
switch(dir){
case "A":x-=val
break
case "S":y-=val
break
case "W":y+=val
break
case "D":x+=val
}
})
print(x+','+y)
let arr = line.split(';') //分割字符串位数组
let reg = /^(A|S|W|D){1}[0-9]{1,2}$/
let newarr = arr.filter(function(item){ //过滤数组
return reg.test(item)
})
let x = 0
let y = 0
newarr.forEach(function(item){ //坐标变换
let dir = item.charAt(0)
let val = Number(item.slice(1))
switch(dir){
case "A":x-=val
break
case "S":y-=val
break
case "W":y+=val
break
case "D":x+=val
}
})
print(x+','+y)