emilia98

Rage Quit

Aug 19th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace _03.RageQuit
  8. {
  9.     class RageQuit
  10.     {
  11.         static void Main()
  12.         {
  13.             string text = Console.ReadLine();
  14.             //var pairs = new Dictionary<string, int>();
  15.             var uniqueSymbols = new HashSet<char>();
  16.             StringBuilder result = new StringBuilder();
  17.  
  18.             Regex pattern = new Regex(@"(?<string>[^0-9]+)(?<number>[0-9]+)");
  19.             MatchCollection matches = pattern.Matches(text);
  20.  
  21.             foreach (Match match in matches)
  22.             {
  23.                 string str = match.Groups["string"].ToString();
  24.                 str = str.ToUpper();
  25.                 int number = int.Parse(match.Groups["number"].ToString());
  26.  
  27.                 for (int cnt = 0; cnt < number; cnt++)
  28.                 {
  29.                     result.Append(str);
  30.  
  31.                     foreach (var symbol in str)
  32.                     {
  33.                         uniqueSymbols.Add(symbol);
  34.                     }
  35.                 }
  36.             }
  37.             Console.WriteLine("Unique symbols used: {0}", uniqueSymbols.Count());
  38.             Console.WriteLine(result);
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment