|
@ -1,5 +1,5 @@ |
|
|
fn main() {
|
|
|
fn main() {
|
|
|
println!("");
|
|
|
|
|
|
|
|
|
println!();
|
|
|
|
|
|
|
|
|
let strs = vec!["is2 Thi1s T4est 3a"];
|
|
|
let strs = vec!["is2 Thi1s T4est 3a"];
|
|
|
|
|
|
|
|
@ -7,7 +7,7 @@ fn main() { |
|
|
println!("{} -> {}", str, order(str));
|
|
|
println!("{} -> {}", str, order(str));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
println!("");
|
|
|
|
|
|
|
|
|
println!();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
fn order(sentence: &str) -> String {
|
|
|
fn order(sentence: &str) -> String {
|
|
@ -16,15 +16,18 @@ fn order(sentence: &str) -> String { |
|
|
|
|
|
|
|
|
for word in sentence.split_whitespace() {
|
|
|
for word in sentence.split_whitespace() {
|
|
|
let n = word.matches(char::is_numeric).collect::<Vec<&str>>()[0];
|
|
|
let n = word.matches(char::is_numeric).collect::<Vec<&str>>()[0];
|
|
|
print!("{:?}\t{:?}\n", n, word);
|
|
|
|
|
|
|
|
|
println!("{:?}\t{:?}", n, word);
|
|
|
}
|
|
|
}
|
|
|
println!("");
|
|
|
|
|
|
|
|
|
println!();
|
|
|
|
|
|
|
|
|
words = sentence.split_ascii_whitespace()
|
|
|
words = sentence.split_ascii_whitespace()
|
|
|
.map(|s| format!("{}{}", s.matches(char::is_numeric).collect::<Vec<&str>>()[0],s))
|
|
|
.map(|s| format!("{}{}", s.matches(char::is_numeric).collect::<Vec<&str>>()[0],s))
|
|
|
.collect();
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
words.sort();
|
|
|
words.sort();
|
|
|
|
|
|
|
|
|
words.iter().map(|w| w.trim_start_matches(char::is_numeric)).collect::<Vec<&str>>().join(" ")
|
|
|
|
|
|
|
|
|
words.iter().map(|w| &w[1..])
|
|
|
|
|
|
.collect::<Vec<&str>>()
|
|
|
|
|
|
.join(" ")
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|