joro_thexfiles

2. Rage Quit

Jul 30th, 2019
435
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.Linq;
  3. using System.Text.RegularExpressions;
  4. using System.Collections.Generic;
  5. using System.Text;
  6.  
  7. namespace _2._Rage_Quit
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string text = Console.ReadLine().ToUpper();
  14.  
  15.             var strBuilder = new StringBuilder();
  16.  
  17.             MatchCollection allSymbolsWithoutDigits = Regex.Matches(text, @"\D");
  18.  
  19.             foreach (Match symbol in allSymbolsWithoutDigits)
  20.             {
  21.                 strBuilder.Append(symbol.Value);
  22.             }
  23.  
  24.             string output = strBuilder.ToString().ToUpper();
  25.  
  26.             int uniqueSymbolsCount = output.Distinct().Count();
  27.  
  28.             Console.WriteLine($"Unique symbols used: {uniqueSymbolsCount}");
  29.  
  30.             strBuilder = new StringBuilder();
  31.  
  32.             var dataWithoutDigits = Regex.Matches(text, @"(?<symbols>\D+)(?<count>\d+)");
  33.  
  34.             foreach (Match match in dataWithoutDigits)
  35.             {
  36.                 string currentSymbolGroup = match.Groups["symbols"].Value;
  37.                 int countOfRepeats = int.Parse(match.Groups["count"].Value);
  38.  
  39.                 for (int i = 0; i < countOfRepeats; i++)
  40.                 {
  41.                     strBuilder.Append(currentSymbolGroup);
  42.                 }
  43.             }
  44.  
  45.             Console.WriteLine(strBuilder);
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment