Advertisement
zdravko7

[C# Advanced Exam] Rage Quit

Jul 19th, 2015
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 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. using System.Threading.Tasks;
  7.  
  8. class RageQuit
  9. {
  10.     static void Main(string[] args)
  11.     {
  12.         string input = Console.ReadLine().ToUpper();
  13.  
  14.         StringBuilder result = new StringBuilder();
  15.  
  16.         string pattern = @".*?[0-9]+";
  17.  
  18.         Regex regex = new Regex(pattern);
  19.  
  20.         MatchCollection matches = regex.Matches(input);
  21.  
  22.         foreach (var match in matches)
  23.         {
  24.             string newMatch = match.ToString();
  25.            
  26.             int counter = int.Parse(Regex.Match(newMatch, "[0-9]+").ToString());
  27.            
  28.             newMatch = Regex.Replace(newMatch, @"[0-9]", "");
  29.  
  30.             for (int i = 0; i < counter; i++)
  31.             {
  32.                 result.Append(newMatch);
  33.             }
  34.         }
  35.  
  36.         Console.WriteLine("Unique symbols used: {0}", CheckUnique(input));
  37.         Console.WriteLine(result);
  38.        
  39.     }
  40.  
  41.     public static int CheckUnique(string input)
  42.     {
  43.         input = input.ToUpper();
  44.         Regex rgx = new Regex(@"[0-9]");
  45.         input = rgx.Replace(input, "");
  46.  
  47.         string unique = new String(input.Distinct().ToArray());
  48.         return unique.Length;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement