svephoto

Rage Quit [C#]

Aug 14th, 2021 (edited)
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4.  
  5. namespace RageQuit_MoreEx
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string text = Console.ReadLine().ToUpper();
  12.  
  13.             string partText = "";
  14.  
  15.             StringBuilder builder = new StringBuilder();
  16.  
  17.             for (int i = 0; i < text.Length; i++)
  18.             {
  19.                 if (!char.IsDigit(text[i]))
  20.                 {
  21.                     partText += text[i];
  22.                 }
  23.  
  24.                 else if (char.IsDigit(text[i]))
  25.                 {
  26.                     string number = text[i].ToString();
  27.  
  28.                     if (i + 1 < text.Length)
  29.                     {
  30.                         if (char.IsDigit(text[i + 1]))
  31.                         {
  32.                             number += text[i + 1];
  33.                             i += 1;
  34.                         }
  35.                     }
  36.  
  37.                     int counter = int.Parse(number);
  38.  
  39.                     for (int j = 0; j < counter; j++)
  40.                     {
  41.                         builder.Append(partText);
  42.                     }
  43.  
  44.                     partText = "";
  45.                 }
  46.             }
  47.  
  48.             string rageMessage = builder.ToString();
  49.             int uniqueSymbolsCount = rageMessage.Distinct().Count();
  50.  
  51.             Console.WriteLine($"Unique symbols used: {uniqueSymbolsCount}");
  52.             Console.WriteLine(builder);
  53.         }
  54.     }
  55. }
  56.  
Add Comment
Please, Sign In to add comment