Guest User

Untitled

a guest
Jun 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. use std::iter::FromIterator;
  2.  
  3. fn main() {
  4.  
  5. // Create vec of future substrings
  6. let mut substrings: Vec<String> = Vec::new();
  7.  
  8. // Add a ")" to the end of the array
  9. let mystr = format!("{}{}", "frog(dogau)tomobile", ")");
  10.  
  11. // Create a vec of the characters converted to string
  12. let mut myvec = mystr.chars().map(|x| x.to_string()).collect::<Vec<String>>();
  13.  
  14. // Sort each string in "myvec"
  15. myvec.into_iter().fold("".to_string(), |substring, chr| {
  16. if chr == "(" || chr == ")" {
  17. substrings.push(substring.to_string());
  18. "".to_string()
  19. } else {
  20. format!("{}{}", substring, chr)
  21. }
  22. });
  23.  
  24. for substring in &mut substrings {
  25. let mut substr_vec = substring.chars().collect::<Vec<char>>();
  26. substr_vec.sort();
  27. *substring = String::from_iter(substr_vec);
  28. }
  29.  
  30. let mut result = "".to_string();
  31.  
  32. println!("{:?}", substrings);
  33. }
Add Comment
Please, Sign In to add comment