Advertisement
social1986

Untitled

Nov 1st, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class WormIpsum
  6. {
  7. public static void Main()
  8. {
  9. var sentenceReg = new Regex(@"^[A-Z][^\.]*\.$");
  10. var wordsReg = new Regex(@"[^\s,\.]+");
  11.  
  12. var inputLine = Console.ReadLine();
  13. while (!inputLine.Equals("Worm Ipsum"))
  14. {
  15. var sentenceMatch = sentenceReg.Match(inputLine);
  16. if (sentenceMatch.Success)
  17. {
  18. var wordsMatches = wordsReg.Matches(inputLine);
  19. foreach (Match match in wordsMatches)
  20. {
  21. var currentWord = match.Value;
  22. if (currentWord.Length != currentWord.Distinct().Count())
  23. {
  24. var symbol = currentWord.GroupBy(x => x).OrderByDescending(x => x.Count()).First().Key;
  25. var newWord = string.Concat(Enumerable.Repeat(symbol, currentWord.Length));
  26. inputLine = Regex.Replace(inputLine, currentWord, newWord);
  27.  
  28. }
  29. }
  30.  
  31. Console.WriteLine(inputLine);
  32. }
  33.  
  34. inputLine = Console.ReadLine();
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement