Advertisement
NastySwipy

Prog. Fundamentals Exam Prep III - 03. Rage Quit

Jun 25th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _14_ExamPreparation3
  7. {
  8.     class Program
  9.     {
  10.       static void Main(string[] args)
  11.         {
  12.             string input = Console.ReadLine();
  13.             string pattern = @"([^\d]+)(\d+)";
  14.             StringBuilder sb = new StringBuilder();
  15.             MatchCollection matches = Regex.Matches(input, pattern);
  16.  
  17.             foreach (Match match in matches)
  18.             {
  19.                 string str = match.Groups[1].ToString().ToUpper();
  20.                 int charCount = int.Parse(match.Groups[2].ToString());
  21.                 for (int i = 0; i < charCount; i++)
  22.                 {
  23.                     sb.Append(str);
  24.                 }
  25.             }
  26.             var count = sb.ToString().Distinct().Count();
  27.             Console.WriteLine($"Unique symbols used: {count}");
  28.             Console.WriteLine(sb);
  29.  
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement