using System;
using System.Linq;
public class Test
{
public static void Main()
{
string str = "qwe rty uiop sdfasdfad dfafsa";
Func<String, Char, String> agg =
((s, c) => Char.IsWhiteSpace(c) && s.Last() == c ? s : s + c);
var chars = str.Aggregate("", agg);
Console.WriteLine(string.Join("", chars));
str = string.Join("", str.Where(c => !Char.IsWhiteSpace(c)));
Console.WriteLine(str);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKCXsKCQlzdHJpbmcgc3RyID0gInF3ZSAgIHJ0eSAgICAgdWlvcCAgIHNkZmFzZGZhZCBkZmFmc2EiOwoKCQlGdW5jPFN0cmluZywgQ2hhciwgU3RyaW5nPiBhZ2cgPQoJCQkoKHMsIGMpID0+IENoYXIuSXNXaGl0ZVNwYWNlKGMpICYmIHMuTGFzdCgpID09IGMgPyBzIDogcyArIGMpOwoJCXZhciBjaGFycyA9IHN0ci5BZ2dyZWdhdGUoIiIsIGFnZyk7CgkJQ29uc29sZS5Xcml0ZUxpbmUoc3RyaW5nLkpvaW4oIiIsIGNoYXJzKSk7CgkJCgkJc3RyID0gc3RyaW5nLkpvaW4oIiIsIHN0ci5XaGVyZShjID0+ICFDaGFyLklzV2hpdGVTcGFjZShjKSkpOwoJCUNvbnNvbGUuV3JpdGVMaW5lKHN0cik7Cgl9Cn0=