joro_thexfiles

2. Rage Quit

Jul 30th, 2019
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 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.             List<char> uniqueSymbols = new List<char>();
  18.            
  19.             MatchCollection allSymbolsWithoutDigits = Regex.Matches(text, @"\D");
  20.  
  21.             foreach (Match symbol in allSymbolsWithoutDigits)
  22.             {
  23.                 strBuilder.Append(symbol.Value);
  24.             }
  25.            
  26.             for (int i = 0; i < strBuilder.Length; i++)
  27.             {
  28.                 if (!uniqueSymbols.Contains(strBuilder[i]))
  29.                 {
  30.                     uniqueSymbols.Add(strBuilder[i]);
  31.                 }
  32.             }
  33.  
  34.             Console.WriteLine($"Unique symbols used: {uniqueSymbols.Count}");
  35.  
  36.             strBuilder = new StringBuilder();
  37.  
  38.             var dataWithoutDigits = Regex.Matches(text, @"(?<symbols>\D+)(?<count>\d+)");
  39.  
  40.             foreach (Match match in dataWithoutDigits)
  41.             {
  42.                 string currentSymbolGroup = match.Groups["symbols"].Value;
  43.                 int countOfRepeats = int.Parse(match.Groups["count"].Value);
  44.  
  45.                 for (int i = 0; i < countOfRepeats; i++)
  46.                 {
  47.                     strBuilder.Append(currentSymbolGroup);
  48.                 }
  49.  
  50.             }
  51.  
  52.             Console.WriteLine(strBuilder);
  53.  
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment