diff --git a/src/main.rs b/src/main.rs index e7a11a9..c0d3f35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,30 @@ fn main() { - println!("Hello, world!"); + println!(""); + + let strs = vec!["is2 Thi1s T4est 3a"]; + + for str in strs { + println!("{} -> {}", str, order(str)); + } + + println!(""); +} + +fn order(sentence: &str) -> String { + + let mut words = vec![]; + + for word in sentence.split_whitespace() { + let n = word.matches(char::is_numeric).collect::>()[0]; + print!("{:?}\t{:?}\n", n, word); + } + println!(""); + + words = sentence.split_ascii_whitespace() + .map(|s| format!("{}{}", s.matches(char::is_numeric).collect::>()[0],s)) + .collect(); + words.sort(); + + words.iter().map(|w| w.trim_start_matches(char::is_numeric)).collect::>().join(" ") + }