using System.Collections.Generic;
internal static class Program
private static void Main()
Console.WriteLine(TextRedactor.RedactInputMessage("ПриВеТик"));
Console.WriteLine(TextRedactor.RedactInputMessage("Елисей"));
Console.WriteLine(TextRedactor.RedactInputMessage("НЕ ОРИ НА МЕНЯ"));
Console.WriteLine(TextRedactor.RedactInputMessage("чебурашка - это слишком длинно. зовите меня просто - Че!"));
Console.WriteLine(TextRedactor.RedactInputMessage("Приффетик йа креведко"));
Console.WriteLine(TextRedactor.RedactInputMessage("ПриФфетик ЙА Креффедко. кАк ДиЛа?"));
Console.WriteLine(TextRedactor.RedactInputMessage("АаА."));
internal static class TextRedactor
public static string RedactInputMessage(string inputMsg)
var words = inputMsg.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < words.Length; i++)
TryToLowercaseLetters(ref words[i]);
ReplaceLetterCombinations(ref words[i]);
СorrectСapitalLettersInSentences(ref words);
var answer = new StringBuilder();
foreach (var word in words)
return answer.ToString();
private static void TryToLowercaseLetters(ref string word)
if (char.IsUpper(word[0]) && word.Length > 1)
var countOfUpperChars = 1;
for (var i = 1; i < word.Length; i++)
if (char.IsUpper(word[i]))
if (countOfUpperChars > 1 && countOfUpperChars < word.Length)
LowercaseAllLettersInWord(ref word);
LowercaseAllLettersInWord(ref word);
private static void СorrectСapitalLettersInSentences(ref string[] words)
var punctuationMarks = new HashSet<char>()
var beginningSentenceIndex = 0;
for (var i = 0; i < words.Length; i++)
foreach (var c in punctuationMarks)
if (!words[i].Contains(c)) continue;
var curWord = words[beginningSentenceIndex];
words[beginningSentenceIndex] = char.ToUpper(curWord[0]) + curWord.Substring(1);
beginningSentenceIndex = i + 1;
private static void ReplaceLetterCombinations(ref string word)
var letterCombinations = new Dictionary<string, string>()
foreach (var combination in letterCombinations.Keys)
if (word.Contains(combination))
word = word.Replace(combination, letterCombinations[combination]);
private static void LowercaseAllLettersInWord(ref string word)