Advertisement
Guest User

Untitled

a guest
Apr 4th, 2019
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 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.             List<char> uniqueSymbols = new List<char>();
  20.  
  21.             foreach (Match match in matched)
  22.             {
  23.                 var value = match.Groups["value"].Value.ToUpper();
  24.                 var times = int.Parse(match.Groups["times"].Value);
  25.  
  26.                 for (int i = 0; i < times; i++)
  27.                 {
  28.                     result.Append(value);
  29.                 }
  30.  
  31.                 if (times > 0)
  32.                 {
  33.                     for (int i = 0; i < value.Length; i++)
  34.                     {
  35.                         if (!uniqueSymbols.Contains(value[i]))
  36.                         {
  37.                             uniqueSymbols.Add(value[i]);
  38.                         }
  39.                     }
  40.                 }
  41.             }
  42.  
  43.  
  44.  
  45.             Console.WriteLine($"Unique symbols used: {uniqueSymbols.Count}");
  46.             Console.WriteLine(result);
  47.  
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement