mausha

WormIpsum

May 2nd, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  1. namespace WormIpsum
  2. {
  3.     using System;
  4.     using System.Linq;
  5.     using System.Text;
  6.  
  7.     public class Ipsum
  8.     {
  9.         public static void Main()
  10.         {
  11.             var input = Console.ReadLine();
  12.  
  13.             while (input != "Worm Ipsum")
  14.             {
  15.                 var sentences = input.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
  16.                 var sentence = sentences[0].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  17.                 if (sentences.Length == 1 && (sentence[0][0] >= 65 && sentence[0][0] <= 90))
  18.                 {
  19.                     for (int i = 0; i < sentence.Length; i++)
  20.                     {
  21.                         var word = sentence[i].ToCharArray();
  22.  
  23.                         var counter = 1;
  24.                         var repeatingSymbol = default(char);
  25.                         for (int j = 0; j < word.Length; j++)
  26.                         {
  27.                             var tempSymbol = word[j];
  28.                             var tempCounter = word.Count(s => s == tempSymbol);
  29.                             if (tempCounter > counter)
  30.                             {
  31.                                 counter = tempCounter;
  32.                                 repeatingSymbol = tempSymbol;
  33.                             }
  34.                         }
  35.  
  36.                         if (counter >= 2)
  37.                         {
  38.                             var newWord = new StringBuilder();
  39.                             for (int k = 0; k < word.Length; k++)
  40.                             {
  41.                                 if (word[k] != ',')
  42.                                 {
  43.                                     newWord.Append(repeatingSymbol);
  44.                                 }
  45.                                 else
  46.                                 {
  47.                                     newWord.Append(word[k]);
  48.                                 }
  49.                             }
  50.  
  51.                             sentence[i] = newWord.ToString();
  52.                         }
  53.                     }
  54.  
  55.                     Console.WriteLine($"{string.Join(" ", sentence)}.");
  56.                 }
  57.  
  58.                 input = Console.ReadLine();
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment