|
@ -1,3 +1,30 @@ |
|
|
fn main() {
|
|
|
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::<Vec<&str>>()[0];
|
|
|
|
|
|
print!("{:?}\t{:?}\n", n, word);
|
|
|
|
|
|
}
|
|
|
|
|
|
println!("");
|
|
|
|
|
|
|
|
|
|
|
|
words = sentence.split_ascii_whitespace()
|
|
|
|
|
|
.map(|s| format!("{}{}", s.matches(char::is_numeric).collect::<Vec<&str>>()[0],s))
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
words.sort();
|
|
|
|
|
|
|
|
|
|
|
|
words.iter().map(|w| w.trim_start_matches(char::is_numeric)).collect::<Vec<&str>>().join(" ")
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|