Pergunta de entrevista da empresa Microsoft

Delete duplicate characters

Resposta da entrevista

Sigiloso

12 de mar. de 2012

using System; using System.Linq; namespace LinkeListShuffle { class Program { static void Main() { const string givenString = "one one two two three four"; //remove duplicate chars var uniqueChars= givenString.ToLower().Distinct().OrderBy(n=>n); foreach (var uniqueChar in uniqueChars) { Console.Write(uniqueChar); } Console.WriteLine(); var delimeters = new []{' ',',','.'}; //remove duplicate words var uniqueWordsString = string.Join(" ",givenString.ToLower().Split(delimeters,StringSplitOptions.RemoveEmptyEntries).Distinct()); Console.WriteLine(uniqueWordsString); Console.Read(); } } }