Guest User

Advanced C# Exam 19 July 2015 03. Rage Quit

a guest
Aug 27th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. class RageQuit
  7. {
  8.     static void Main()
  9.     {        
  10.         string input = Console.ReadLine().ToUpper();        
  11.         var bigList = new List<char>();
  12.         var currlist = new List<char>();
  13.  
  14.         for (int i = 0; i < input.Length; i++)
  15.         {
  16.             char ch = input[i];
  17.  
  18.             if (!Char.IsNumber(ch))
  19.             {
  20.                 currlist.Add(ch);
  21.             }
  22.  
  23.             if (Char.IsNumber(ch))
  24.             {
  25.                 int count = 0;
  26.                 if (i < input.Length - 1 && Char.IsNumber(input[i + 1]))
  27.                 {
  28.                     string str = input.Substring(i, 2);
  29.                     count = int.Parse(str.ToString());
  30.                 }
  31.                 else
  32.                 {
  33.                     count = int.Parse(ch.ToString());
  34.                 }
  35.  
  36.                 if (count > 0)
  37.                 {
  38.                     for (int j = 0; j < count; j++)
  39.                     {
  40.                         bigList.AddRange(currlist);
  41.                     }
  42.                 }                
  43.                 currlist.Clear();
  44.             }
  45.         }
  46.         string result = new string(bigList.ToArray());
  47.         Console.WriteLine("Unique symbols used: {0}", result.Distinct().Count());
  48.         Console.WriteLine(result);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment