Guest User

Untitled

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