Advertisement
Guest User

Untitled

a guest
Dec 30th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 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 _04_Rage_Quit
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. string input = Console.ReadLine().ToUpper();
  15.  
  16. //var allSymbols = new string(input.Where(x => !char.IsDigit(x)).ToArray());
  17. var uniqueSymbols = new Dictionary<char, int>();
  18. string pattern = @"([^\d]+)(\d+)";
  19. MatchCollection matches = Regex.Matches(input, pattern);
  20. StringBuilder sb = new StringBuilder();
  21. foreach (Match item in matches)
  22. {
  23. string characters = item.Groups[1].ToString();
  24. int repeatString = int.Parse(item.Groups[2].ToString());
  25. if (repeatString == 0)
  26. continue;
  27. for (int i = 0; i < characters.Length; i++)
  28. {
  29. var currentElement = characters[i];
  30. if (!uniqueSymbols.ContainsKey(currentElement))
  31. {
  32. uniqueSymbols[currentElement] = 1;
  33. }
  34. }
  35. for (int i = 0; i < repeatString; i++)
  36. {
  37. sb.Append(characters);
  38. }
  39. }
  40.  
  41. Console.WriteLine($"Unique symbols used: {uniqueSymbols.Keys.Count}");
  42.  
  43. Console.WriteLine(sb.ToString());
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement