Advertisement
Guest User

Worm Ipsum

a guest
Jun 7th, 2017
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace WormIpsum
  9. {
  10. class WormIpsum
  11. {
  12. static void Main(string[] args)
  13. {
  14. var input = Console.ReadLine();
  15.  
  16. while (input!= "Worm Ipsum")
  17. {
  18. var inputToCkeck = input.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
  19.  
  20. if (!Char.IsUpper(input[0]) || inputToCkeck.Length!=1)
  21. {
  22. input = Console.ReadLine();
  23. continue;
  24. }
  25.  
  26. var inputArgs = input.Split(new char[] { ' ', ',','.' }, StringSplitOptions.RemoveEmptyEntries);
  27.  
  28. foreach (var word in inputArgs)
  29. {
  30. int maxCount = 0;
  31. string maxWord = "";
  32. var maxChar = ' ';
  33.  
  34. for (int i = 0; i < word.Length-1; i++)
  35. {
  36. int currentCount = 0;
  37. char currentChar = word[i];
  38. int index = word.IndexOf(currentChar);
  39.  
  40. while (index!=-1)
  41. {
  42. currentCount += 1;
  43.  
  44. if (currentCount>maxCount)
  45. {
  46. maxCount = currentCount;
  47. maxWord = word;
  48. maxChar = currentChar;
  49. }
  50.  
  51. index = word.IndexOf(currentChar, index+1);
  52. }
  53.  
  54. if (maxCount >= 2)
  55. {
  56. input = input.Replace(maxWord, new string(maxChar, maxWord.Length));
  57. }
  58. }
  59. }
  60. Console.WriteLine(input);
  61. input = Console.ReadLine();
  62. }
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement