fork download
  1. use std::io;
  2. use std::io::prelude::*;
  3.  
  4. fn compress(first: &str, second: &str) -> String {
  5. let first: String = String::from(first);
  6. let second: String = String::from(second);
  7. let len1: usize = first.len();
  8. let len2: usize = second.len();
  9.  
  10. for i in 0..(len1) {
  11. let char_count: usize = len1 - i;
  12. if char_count <= len2 && first[i..len1] == second[0..char_count] {
  13. return format!("{}{}", first[0..i].to_owned(), second);
  14. }
  15. }
  16. if len1 == 0 {
  17. return format!("{}", second);
  18. }
  19. else {
  20. return format!("{} {}", first, second);
  21. }
  22. }
  23.  
  24. fn main() {
  25. let stdin = io::stdin();
  26. for line in stdin.lock().lines() {
  27. let ans: String = line.unwrap()
  28. .split(" ")
  29. .fold(String::new(), |acc, x| compress(&acc, x));
  30. println!("{}", ans);
  31. }
  32. }
Success #stdin #stdout 0s 14920KB
stdin
I heard the pastor sing live verses easily.
Deep episodes of Deep Space Nine came on the television only after the news.
Digital alarm clocks scare area children.
stdout
I heard the pastor sing liverses easily.
Deepisodes of Deep Space Nine came on the televisionly after the news.
Digitalarm clockscarea children.