Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 02. Rage Quit
- 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.
- 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".
- 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.
- 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.
- Input
- • The input data should be read from the console.
- • It consists of a single line holding a series of string-number sequences.
- • The input data will always be valid and in the format described. There is no need to check it explicitly.
- Output
- • The output should be printed on the console. It should consist of exactly two lines.
- • On the first line, print the number of unique symbols used in the message.
- • On the second line, print the resulting rage message itself.
- Constraints
- • The count of string-number pairs will be in the range [1 … 20 000].
- • Each string will contain any character except digits. The length of each string will be in the range [1 … 20].
- • The repeat count for each string will be an integer in the range [0 … 20].
- • Allowed working time for your program: 0.3 seconds. Allowed memory: 64 MB.
- Examples
- Input Output Comments
- a3 Unique symbols used: 1 We have just one string-number pair. The symbol is 'a', convert it
- AAA to uppercase and repeat 3 times: AAA.
- Only one symbol is used ('A').
- aSd2&5s@1 Unique symbols used: 5 "aSd" is converted to "ASD" and repeated twice; "&" is repeated 5 times;
- ASDASD&&&&&S@ "s@" is converted to "S@" and repeated once.
- 5 symbols are used: 'A', 'S', 'D', '&' and '@'.
- e-!btI17z=E:DMJ19U1Tvg VQ>11 Unique symbols used: 53
- P"qCmo.-0YHYu~o%/%b.}a[=d15f E-!BTIE-!BTIE-!BTIE....
- z^"{0^/pg.Ft{W12`aD<l&$W&)*y .......................
- F1WLV9_GmTf(d0($!$`e/{D'xi]- .......................
- ~17 *%p"%|N>zq@ %xBD18<Y(fHh .......................
- `@gu#Z#p"Z<v13fI]':\Iz.17*W: .......................
- \mwV`z-15g@hUYE{_$~}+X%*nytkW15 ..............+X%*NYTKW
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- public class Program
- {
- public static void Main()
- {
- var inputData = Console.ReadLine().ToUpper(); With Regex!
- var repeatedSymbols = new List<string>();
- var listUniqueSymbols = new List<char>();
- var pattern = @"(?<Symbols>\D+)(?<Digits>\d+)";
- var matchString = Regex.Matches(inputData, pattern);
- foreach (Match item in matchString)
- {
- var symbols = item.Groups["Symbols"].Value;
- var numbers = int.Parse(item.Groups["Digits"].Value);
- var counter = 0;
- for (int i = 0; i < numbers; i++)
- {
- if (counter == 0)
- {
- counter++;
- foreach (var symbol in symbols)
- {
- if (!listUniqueSymbols.Contains(symbol) == true)
- {
- listUniqueSymbols.Add(symbol);
- }
- }
- }
- repeatedSymbols.Add(symbols);
- }
- }
- Console.WriteLine($"Unique symbols used: {listOfUniqueSymbols.Count}\n{string.Join("", repeatedSymbols)}");
- //var inputData = Console.ReadLine().ToUpper(); Without Regex!
- //var concatenatedSymbols = "";
- //var multiply = "";
- //var counter = 0;
- //var rageMessage = new List<string>();
- //var listUniqueSymbols = new List<char>();
- //for (int i = 0; i < inputData.Length; i++)
- //{
- // counter++;
- // if (Char.IsDigit(inputData[i]) == true)
- // {
- // while (Char.IsDigit(inputData[i]) == true)
- // {
- // multiply += inputData[i];
- // if (inputData.Length == counter)
- // {
- // break;
- // }
- // i++;
- // counter++;
- // }
- // if (inputData.Length != counter)
- // {
- // i--;
- // counter--;
- // if (multiply.Length == 2)
- // {
- // i--;
- // counter--;
- // }
- // }
- // if (multiply == "0")
- // {
- // concatenatedSymbols = "";
- // multiply = "";
- // continue;
- // }
- // for (int c = 0; c < concatenatedSymbols.Length; c++)
- // {
- // if (!listUniqueSymbols.Contains(concatenatedSymbols[c]))
- // {
- // listUniqueSymbols.Add(concatenatedSymbols[c]);
- // }
- // }
- // for (int b = 1; b <= int.Parse(multiply); b++)
- // {
- // rageMessage.Add(concatenatedSymbols);
- // }
- // concatenatedSymbols = "";
- // multiply = "";
- // }
- // else
- // {
- // concatenatedSymbols += inputData[i];
- // }
- //}
- //Console.WriteLine($"Unique symbols used: {listUniqueSymbols.Count}\n{string.Join("", rageMessage)}");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement