Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace WormIpsum
- {
- class WormIpsum
- {
- static void Main(string[] args)
- {
- var input = Console.ReadLine();
- while (input!= "Worm Ipsum")
- {
- var inputToCkeck = input.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
- if (!Char.IsUpper(input[0]) || inputToCkeck.Length!=1)
- {
- input = Console.ReadLine();
- continue;
- }
- var inputArgs = input.Split(new char[] { ' ', ',','.' }, StringSplitOptions.RemoveEmptyEntries);
- foreach (var word in inputArgs)
- {
- int maxCount = 0;
- string maxWord = "";
- var maxChar = ' ';
- for (int i = 0; i < word.Length-1; i++)
- {
- int currentCount = 0;
- char currentChar = word[i];
- int index = word.IndexOf(currentChar);
- while (index!=-1)
- {
- currentCount += 1;
- if (currentCount>maxCount)
- {
- maxCount = currentCount;
- maxWord = word;
- maxChar = currentChar;
- }
- index = word.IndexOf(currentChar, index+1);
- }
- if (maxCount >= 2)
- {
- input = input.Replace(maxWord, new string(maxChar, maxWord.Length));
- }
- }
- }
- Console.WriteLine(input);
- input = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement