joro_thexfiles

2. Rage Quit

Aug 1st, 2019
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _2._Rage_Quit___third_try
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string text = Console.ReadLine().ToUpper();
  13.  
  14.             StringBuilder sb = new StringBuilder();
  15.  
  16.             string[] symbolArr = text.Split(new char[] { '0', '1', '2', '3', '4', '5','6', '7', '8', '9' }, StringSplitOptions.RemoveEmptyEntries);
  17.  
  18.             MatchCollection matches = Regex.Matches(text, @"[\d]+");
  19.                                
  20.             int[] digits = new int[matches.Count];
  21.  
  22.             int count = 0;
  23.  
  24.             foreach (Match digit in matches)
  25.             {
  26.                 digits[count] = int.Parse(digit.Value) ;
  27.                 count++;
  28.             }
  29.  
  30.             for (int i = 0; i < digits.Length; i++)
  31.             {
  32.                 int countOfRepeats = digits[i];
  33.  
  34.                 for (int z = 0; z < countOfRepeats; z++)
  35.                 {
  36.                     sb.Append(symbolArr[i]);
  37.                 }
  38.             }
  39.  
  40.             char[] uniqueSymbols = sb.ToString().Distinct().ToArray();
  41.  
  42.             Console.WriteLine($"Unique symbols used: {uniqueSymbols.Length}");
  43.  
  44.             Console.WriteLine(sb);
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment