Advertisement
Guest User

Untitled

a guest
Apr 4th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace TestCodeProject
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string input = Console.ReadLine();
  13.  
  14.             string regex = @"(?<value>[^0-9]+)(?<times>[0-9]+)";
  15.             MatchCollection matched = Regex.Matches(input, regex);
  16.  
  17.             StringBuilder result = new StringBuilder();
  18.  
  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.  
  34.                     for (int i = 0; i < value.Length; i++)
  35.                     {
  36.                         if (!uniqueSymbols.Contains(value[i]))
  37.                         {
  38.                             uniqueSymbols.Add(value[i]);
  39.                         }
  40.                     }
  41.                 }
  42.             }
  43.  
  44.  
  45.             Console.WriteLine($"Unique symbols used: {uniqueSymbols.Count}");
  46.             Console.WriteLine(result);
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement