题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import Foundation var x = 0 var y = 0 while let line = readLine() { let list = line.components(separatedBy: ";") for item in list { if item.count > 1 { if item.hasPrefix("A") { x -= getValue(item) } else if item.hasPrefix("D") { x += getValue(item) } else if item.hasPrefix("W") { y += getValue(item) } else if item.hasPrefix("S") { y -= getValue(item) } } } print("\(x),\(y)") } func getValue(_ text: String) -> Int { let value1 = text.substring(from: 1) if let value2 = Int(value1) { return value2 } else { return 0 } }