题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
pub fn caculate_location() -> (i32, i32) { let mut input = String::new(); std::io::stdin() .read_line(&mut input) .expect("Failed to read line"); input .trim() .split(";") .map(|item| { if item.len() < 2 { (0, 0) } else { let (s1, s2) = item.split_at(1); if let Ok(value) = s2.parse::<i32>() { if s1 == "A" { (-value, 0) } else if s1 == "D" { (value, 0) } else if s1 == "W" { (0, value) } else if s1 == "S" { (0, -value) } else { (0, 0) } } else { (0, 0) } } }) .fold((0, 0), |acc, x| (acc.0 + x.0, acc.1 + x.1)) } fn main() { let v=caculate_location(); println!("{},{}",v.0,v.1); }