Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. static BSPACE_CHAR: char = '#';
  2.  
  3. pub fn stack_based(arg1: &String, arg2: &String) -> bool {
  4. let process_string = |s: &String| -> String {
  5. let mut result = String::with_capacity(s.len());
  6.  
  7. for c in s.chars() {
  8. if c != BSPACE_CHAR {
  9. result.push(c);
  10. } else {
  11. result.pop();
  12. }
  13. }
  14. result
  15. };
  16.  
  17. process_string(arg1) == process_string(arg2)
  18. }
  19.  
  20. #[cfg(test)]
  21. mod tests {
  22. #[test]
  23. fn stack_based_test() {
  24. assert_eq!(
  25. super::stack_based(&String::from("K#Test##+#"), &String::from("Test##ξ#")),
  26. true
  27. );
  28. assert_eq!(
  29. super::stack_based(&String::from("##деленe#ити"), &String::from("делениy#ти")),
  30. true
  31. );
  32. }
  33. }
  34.  
  35. fn main() {
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement