Advertisement
bullit3189

Rage Quit - String and Text Proccessing

Feb 17th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4.  
  5. namespace _10RageQuit
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. char[] input = Console.ReadLine().ToUpper().ToCharArray();
  12. string toBeRepeated = "";
  13. string repetition = "";
  14. StringBuilder result = new StringBuilder();
  15.  
  16. for (int i = 0; i < input.Length; i++)
  17. {
  18. if (char.IsDigit(input[i]))
  19. {
  20. repetition += input[i].ToString();
  21.  
  22. if (i + 1 < input.Length && char.IsDigit(input[i + 1]))
  23. {
  24. repetition += input[i + 1].ToString();
  25. }
  26.  
  27. int counter = int.Parse(repetition);
  28.  
  29. if (counter == 0) // Don't need to add that to the result.
  30. {
  31. toBeRepeated = "";
  32. repetition = "";
  33. }
  34. else
  35. {
  36. for (int j = 0; j < counter; j++)
  37. {
  38. result.Append(toBeRepeated);
  39.  
  40. if (j == counter - 1) // If we are at the last iteration we clear the strings.
  41. {
  42. toBeRepeated = "";
  43. repetition = "";
  44. }
  45. }
  46. }
  47. }
  48. else
  49. {
  50. toBeRepeated += input[i];
  51. }
  52. }
  53.  
  54. int uniqueSymbols = result.ToString().Distinct().Count();
  55. string resultString = result.ToString();
  56.  
  57. Console.WriteLine($"Unique symbols used: {uniqueSymbols}");
  58. Console.WriteLine(resultString);
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement