fork download
  1. using static System.Console;
  2.  
  3. string f(string s)
  4. {
  5. return s.Aggregate("", (x, y) => x + (y == ' ' ? x.EndsWith(" ") ? "" : " " : y));
  6. }
  7.  
  8. foreach (string s in new[] {"abc def ghi", "a b c", " a ", " a", "a ", " ", ""}) {
  9. WriteLine($"\"{s}\" -> \"{f(s)}\"");
  10. }
Success #stdin #stdout 0.06s 30392KB
stdin
Standard input is empty
stdout
"abc def        ghi" -> "abc    def    ghi"
"a b     c" -> "a    b    c"
" a " -> "    a    "
"  a" -> "    a"
"a  " -> "a    "
" " -> "    "
"" -> ""