Advertisement
knoteva

Untitled

Jul 30th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5. using System.Diagnostics;
  6.  
  7. namespace RageQuit
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Stopwatch timer = new Stopwatch();
  14.             timer.Start();
  15.             string pattern = @"(?<stringName>[^0-9]+)(?<count>\d+)";
  16.             string input = Console.ReadLine();
  17.             var match = Regex.Matches(input, pattern);
  18.             var sb = new StringBuilder();
  19.             //int count = 0;
  20.             //string matchedElement = string.Empty;
  21.             foreach (Match item in match)
  22.             {
  23.                 string currentSymbol = item.Groups["stringName"].Value;
  24.                 int repeatCount = int.Parse(item.Groups["count"].Value);
  25.                 for (int i = 0; i < repeatCount; i++)
  26.                 {
  27.                     sb.Append(currentSymbol);
  28.                 }
  29.                 //matchedElement += item;
  30.             }
  31.             var result = sb.ToString();
  32.             result = result.ToUpper();
  33.             //matchedElement = matchedElement.ToUpper();
  34.             //string isContains = "";
  35.             //for (int i = 0; i < matchedElement.Length; i++)
  36.             //{
  37.             //    char currentSymbol = matchedElement[i];
  38.             //    if (!Char.IsDigit(currentSymbol) && !isContains.Contains(currentSymbol))
  39.             //    {
  40.             //        count++;
  41.             //        isContains += currentSymbol;
  42.             //    }
  43.             //}
  44.             Console.WriteLine($"Unique symbols used: {result.Distinct().Count()}");
  45.             Console.WriteLine(result);
  46.             timer.Stop();
  47.  
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement