Advertisement
YavorGrancharov

03. Rage Quit(Regex)

Nov 4th, 2017
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Rage_Quit
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string input = Console.ReadLine();
  13.  
  14.             string toRepeat = @"([^\d]+)([\d]+)";
  15.  
  16.             List<string> list = new List<string>();
  17.             foreach (Match m in Regex.Matches(input,toRepeat))
  18.             {              
  19.                 string repeated = m.Groups[1].ToString().ToUpper();
  20.                 var newstr = string.Concat(Enumerable.Repeat(repeated, int.Parse(m.Groups[2].Value)));
  21.                 list.Add(newstr);
  22.             }
  23.             string result = string.Join("",list);
  24.             Console.WriteLine("Unique symbols used: {0}",result.Where(x => !char.IsDigit(x)).Distinct().Count());
  25.             Console.WriteLine(result);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement