Advertisement
JulianJulianov

11.RegularExpressionsMoreExercise - Rage Quit

May 18th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.75 KB | None | 0 0
  1. 02. Rage Quit
  2. Every gamer knows what rage-quitting means. It’s basically when you’re just not good enough and you blame everybody else for losing a game. You press the CAPS LOCK key on the keyboard and flood the chat with gibberish to show your frustration.
  3. Chochko is a gamer, and a bad one at that. He asks for your help; he wants to be the most annoying kid in his team, so when he rage-quits he wants something truly spectacular. He’ll give you a series of strings followed by non-negative numbers, e.g. "a3"; you need to print on the console each string repeated N times; convert the letters to uppercase beforehand. In the example, you need to write back "AAA".
  4. On the output, print first a statistic of the number of unique symbols used (the casing of letters is irrelevant, meaning that 'a' and 'A' are the same); the format shoud be "Unique symbols used {0}". Then, print the rage message itself.
  5. The strings and numbers will not be separated by anything. The input will always start with a string and for each string there will be a corresponding number. The entire input will be given on a single line; Chochko is too lazy to make your job easier.
  6. Input
  7. • The input data should be read from the console.
  8. • It consists of a single line holding a series of string-number sequences.
  9. • The input data will always be valid and in the format described. There is no need to check it explicitly.
  10. Output
  11. • The output should be printed on the console. It should consist of exactly two lines.
  12. • On the first line, print the number of unique symbols used in the message.
  13. • On the second line, print the resulting rage message itself.
  14. Constraints
  15. • The count of string-number pairs will be in the range [120 000].
  16. • Each string will contain any character except digits. The length of each string will be in the range [120].
  17. • The repeat count for each string will be an integer in the range [020].
  18. • Allowed working time for your program: 0.3 seconds. Allowed memory: 64 MB.
  19. Examples
  20. Input                           Output                      Comments
  21. a3                              Unique symbols used: 1      We have just one string-number pair. The symbol is 'a', convert it
  22.                                 AAA                         to uppercase and repeat 3 times: AAA.
  23.                                                             Only one symbol is used ('A').
  24. aSd2&5s@1                       Unique symbols used: 5      "aSd" is converted to "ASD" and repeated twice; "&" is repeated 5 times;
  25.                                 ASDASD&&&&&S@               "s@" is converted to "S@" and repeated once.
  26.                                                             5 symbols are used: 'A', 'S', 'D', '&' and '@'.
  27. e-!btI17z=E:DMJ19U1Tvg VQ>11    Unique symbols used: 53
  28. P"qCmo.-0YHYu~o%/%b.}a[=d15f    E-!BTIE-!BTIE-!BTIE....
  29. z^"{0^/pg.Ft{W12`aD<l&$W&)*y    .......................
  30. F1WLV9_GmTf(d0($!$`e/{D'xi]-    .......................
  31. ~17 *%p"%|N>zq@ %xBD18<Y(fHh    .......................
  32. `@gu#Z#p"Z<v13fI]':\Iz.17*W:    .......................
  33. \mwV`z-15g@hUYE{_$~}+X%*nytkW15 ..............+X%*NYTKW
  34.  
  35.  
  36. using System;
  37. using System.Collections.Generic;
  38. using System.Text.RegularExpressions;
  39.  
  40. public class Program
  41. {
  42.     public static void Main()
  43.     {
  44.         var inputData = Console.ReadLine().ToUpper();                           With Regex!
  45.         var repeatedSymbols = new List<string>();
  46.         var listUniqueSymbols = new List<char>();
  47.         var pattern = @"(?<Symbols>\D+)(?<Digits>\d+)";
  48.         var matchString = Regex.Matches(inputData, pattern);
  49.        
  50.         foreach (Match item in matchString)
  51.         {
  52.             var symbols = item.Groups["Symbols"].Value;
  53.             var numbers = int.Parse(item.Groups["Digits"].Value);
  54.             var counter = 0;
  55.            
  56.             for (int i = 0; i < numbers; i++)
  57.             {
  58.                 if (counter == 0)
  59.                 {
  60.                     counter++;
  61.                     foreach (var symbol in symbols)
  62.                     {  
  63.                         if (!listUniqueSymbols.Contains(symbol) == true)
  64.                         {
  65.                             listUniqueSymbols.Add(symbol);
  66.                         }
  67.                      }
  68.                  }
  69.                  repeatedSymbols.Add(symbols);
  70.              }
  71.          }
  72.          Console.WriteLine($"Unique symbols used: {listOfUniqueSymbols.Count}\n{string.Join("", repeatedSymbols)}");
  73.  
  74.  
  75.  
  76.  
  77.  
  78.             //var inputData = Console.ReadLine().ToUpper();              Without Regex!
  79.             //var concatenatedSymbols = "";
  80.             //var multiply = "";
  81.             //var counter = 0;
  82.             //var rageMessage = new List<string>();
  83.             //var listUniqueSymbols = new List<char>();
  84.            
  85.             //for (int i = 0; i < inputData.Length; i++)
  86.             //{
  87.             //    counter++;
  88.             //    if (Char.IsDigit(inputData[i]) == true)
  89.             //    {
  90.             //        while (Char.IsDigit(inputData[i]) == true)
  91.             //        {
  92.             //            multiply += inputData[i];
  93.             //            if (inputData.Length == counter)
  94.             //            {
  95.             //                break;
  96.             //            }
  97.             //            i++;
  98.             //            counter++;
  99.             //        }
  100.             //        if (inputData.Length != counter)
  101.             //        {
  102.             //            i--;
  103.             //            counter--;
  104.             //            if (multiply.Length == 2)
  105.             //            {
  106.             //                i--;
  107.             //                counter--;
  108.             //            }
  109.             //        }
  110.             //        if (multiply == "0")
  111.             //        {
  112.             //            concatenatedSymbols = "";
  113.             //            multiply = "";
  114.             //            continue;
  115.             //        }
  116.             //        for (int c = 0; c < concatenatedSymbols.Length; c++)
  117.             //        {
  118.             //            if (!listUniqueSymbols.Contains(concatenatedSymbols[c]))
  119.             //            {
  120.             //                listUniqueSymbols.Add(concatenatedSymbols[c]);
  121.             //            }
  122.             //        }
  123.             //        for (int b = 1; b <= int.Parse(multiply); b++)
  124.             //        {
  125.             //            rageMessage.Add(concatenatedSymbols);
  126.             //        }
  127.             //        concatenatedSymbols = "";
  128.             //        multiply = "";
  129.             //    }
  130.             //    else
  131.             //    {
  132.             //        concatenatedSymbols += inputData[i];
  133.             //    }
  134.             //}
  135.             //Console.WriteLine($"Unique symbols used: {listUniqueSymbols.Count}\n{string.Join("", rageMessage)}");
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement