Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::iter::FromIterator;
- fn main() {
- // Create vec of future substrings
- let mut substrings: Vec<String> = Vec::new();
- // Add a ")" to the end of the array
- let mystr = format!("{}{}", "frog(dogau)tomobile", ")");
- // Create a vec of the characters converted to string
- let mut myvec = mystr.chars().map(|x| x.to_string()).collect::<Vec<String>>();
- // Sort each string in "myvec"
- myvec.into_iter().fold("".to_string(), |substring, chr| {
- if chr == "(" || chr == ")" {
- substrings.push(substring.to_string());
- "".to_string()
- } else {
- format!("{}{}", substring, chr)
- }
- });
- for substring in &mut substrings {
- let mut substr_vec = substring.chars().collect::<Vec<char>>();
- substr_vec.sort();
- *substring = String::from_iter(substr_vec);
- }
- let mut result = "".to_string();
- println!("{:?}", substrings);
- }
Add Comment
Please, Sign In to add comment