bullit3189

RageQuit - Regex

Mar 20th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Text;
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. string input = Console.ReadLine().ToUpper();
  12.  
  13. StringBuilder result = new StringBuilder();
  14.  
  15. string pattern = @"((?<letters>[\D]+)(?<num>\d+))";
  16.  
  17. MatchCollection matches = Regex.Matches(input,pattern);
  18.  
  19. foreach (Match match in matches)
  20. {
  21. string letters = match.Groups["letters"].Value;
  22. int num = int.Parse(match.Groups["num"].Value);
  23.  
  24. for (int i=0; i<num; i++)
  25. {
  26. result.Append(letters);
  27. }
  28. }
  29.  
  30. int symbols = result.ToString().Distinct().Count();
  31.  
  32. Console.WriteLine("Unique symbols used: {0}",symbols);
  33. Console.WriteLine(result.ToString());
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment