Advertisement
martyz

Rage Quit - regex +linq - one Line :)

Jan 23rd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace RageQuit
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var collection = Regex.Matches(Console.ReadLine(), @"([^0-9]+)(\d*)");
  12.  
  13.             Console.WriteLine("Unique symbols used: {1}\n{0}", string.Join("", collection
  14.                .Cast<Match>()
  15.                 .Select(m => string.Join("", (Enumerable.Repeat(m.Groups[1].ToString().ToUpper(), int.Parse(m.Groups[2].ToString())))))
  16.                 .ToList()), new string(string.Join("", collection.Cast<Match>().Where(y => y.Groups[2].ToString() != "0").Select(x => x.Groups[1].ToString().ToUpper()).ToArray()).Distinct().ToArray()).Count());
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement