Program.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Text;
  3. namespace D10._1
  4. {
  5. public class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. if (args.Length < 1) throw new ArgumentException();
  10. string input = args[0];
  11. int tries = 40;
  12. Apply(ref input, ref tries);
  13. Console.WriteLine($"The answer is : {input.Length}");
  14. }
  15. public static void Apply(ref string input, ref int tries)
  16. {
  17. while (tries > 0)
  18. {
  19. var ninput = new StringBuilder("");
  20. int i = 0;
  21. while (i < input.Length)
  22. {
  23. char current = input[i];
  24. int count = 0;
  25. while (i < input.Length && input[i] == current)
  26. {
  27. count++;
  28. i++;
  29. }
  30. ninput.Append(count);
  31. ninput.Append(current);
  32. }
  33. input = ninput.ToString();
  34. tries--;
  35. }
  36. }
  37. }
  38. }