题解 | #坐标移动#
坐标移动
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"); let mut loc = (0, 0); input.trim().split(";").for_each(|item| { if item.starts_with("A") { if let Ok(value) = item.split_at(1).1.parse::<i32>() { loc.0 -= value; } } else if item.starts_with("S") { if let Ok(value) = item.split_at(1).1.parse::<i32>() { loc.1 -= value; } } else if item.starts_with("W") { if let Ok(value) = item.split_at(1).1.parse::<i32>() { loc.1+=value; } } else if item.starts_with("D") { if let Ok(value) = item.split_at(1).1.parse::<i32>() { loc.0+=value; } } }); loc } fn main() { let v=caculate_location(); println!("{},{}",v.0,v.1); }