IPetrov007

RageQuit

Apr 19th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 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 _03_RageQuit
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. var inputString = Console.ReadLine();
  15.  
  16. var uniqueString = new List<string>();
  17. for (int i = 0; i < inputString.Length; i++)
  18. {
  19. var currentChar = inputString[i].ToString().ToUpper();
  20. var num = -1;
  21. if (!int.TryParse(currentChar.ToString(), out num))
  22. {
  23. uniqueString.Add(currentChar);
  24. }
  25. }
  26. uniqueString = uniqueString.Distinct().ToList();
  27.  
  28. var pattern = @"([^\d]+)(\d{1,2})";
  29. var regex = new Regex(pattern);
  30.  
  31. var matches = regex.Matches(inputString);
  32.  
  33. var sb = new StringBuilder();
  34.  
  35. foreach (Match match in matches)
  36. {
  37. var currentString = match.Groups[1].Value.ToUpper();
  38. var currentCount = int.Parse(match.Groups[2].Value);
  39. if (currentCount <= 20)
  40. {
  41. for (int i = 0; i < currentCount; i++)
  42. {
  43. sb.Append(currentString);
  44. }
  45. }
  46. }
  47. Console.WriteLine($"Unique symbols used: {uniqueString.Count}");
  48. Console.WriteLine(sb.ToString());
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment