fork download
  1. #include <iostream>
  2. #include <regex>
  3.  
  4. std::string condense (std::string str) {
  5. std::regex r("(.+)\\s+\\1");
  6. return regex_replace(str, r, "$1");
  7. }
  8.  
  9. int main() {
  10. std::vector<std::string> lines = {"I heard the pastor sing live verses easily.",
  11. "Deep episodes of Deep Space Nine came on the television only after the news.",
  12. "Digital alarm clocks scare area children."};
  13.  
  14. for (auto line : lines) std::cout << condense(line) << std::endl;
  15. }
Success #stdin #stdout 0s 15344KB
stdin
Standard input is empty
stdout
I heard the pastor sing liverses easily.
Deepisodes of Deep Space Nine came on the televisionly after the news.
Digitalarm clockscarea children.