Guest User

Untitled

a guest
Apr 4th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 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.  
  7. namespace Problem10RageQuit
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.  
  15.             string regex = @"(?<value>[^0-9]+)(?<times>[0-9]+)";
  16.             MatchCollection matched = Regex.Matches(input, regex);
  17.  
  18.             StringBuilder result = new StringBuilder();
  19.  
  20.             foreach (Match match in matched)
  21.             {
  22.                 var value = match.Groups["value"].Value;
  23.                 var times = int.Parse(match.Groups["times"].Value);
  24.  
  25.                 for (int i = 0; i < times; i++)
  26.                 {
  27.                     result.Append(value.ToUpper());
  28.                 }
  29.             }
  30.  
  31.             int uniqueSymbolsCount = result.ToString().Distinct().Count();
  32.  
  33.             Console.WriteLine($"Unique symbols used: {uniqueSymbolsCount}");
  34.             Console.WriteLine(result);
  35.  
  36.         }
  37.     }
  38. }
Add Comment
Please, Sign In to add comment