Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

IvaYorgova avatar IvaYorgova 17 Точки

Regular Expressions - More Exercise - 02.Rage Quit

Здравейте,

успях да докарам до 90/100. На един от тестовете дава Time Limit.

Ще съм много благодарна за малко помощ!

Ето задачата и кода:

 

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

AAA

We have just one string-number pair. The symbol is 'a', convert it to uppercase and repeat 3 times: AAA.

Only one symbol is used ('A').

aSd2&5s@1

Unique symbols used: 5

ASDASD&&&&&S@

"aSd" is converted to "ASD" and repeated twice; "&" is repeated 5 times; "s@" is converted to "S@" and repeated once.

5 symbols are used: 'A', 'S', 'D', '&' and '@'.

 

-------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace _02.RageQuit
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            string pattern = @"([\D]+)([0-9]+)";

            MatchCollection matches = Regex.Matches(input, pattern);

            StringBuilder message = new StringBuilder();

            int symbolsCount = 0;

            foreach (Match item in matches)
            {
                string letters = item.Groups[1].Value;
                int number = int.Parse(item.Groups[2].Value);

                for (int i = 0; i < number; i++)
                {
                    message.Append(letters);
                }
            }

            string gibberish = message.ToString().ToUpper();
            symbolsCount = gibberish.Distinct().Count();

            Console.WriteLine($"Unique symbols used: {symbolsCount}");
            Console.WriteLine(gibberish);

        }
    }
}

Тагове:
1
C# Fundamentals 04/08/2020 10:10:14
daniel123123 avatar daniel123123 27 Точки

C# 100/100

using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
class SoftUni {
    static void Main() {
        var s = new StringBuilder();
        foreach (Match m in Regex.Matches(Console.ReadLine().ToUpper(), @"([^\d]+)([\d]+)"))
            for (int i = 0; i < int.Parse(m.Groups[2].Value); i++) s.Append(m.Groups[1].Value);
        Console.Write($"Unique symbols used: {s.ToString().Distinct().Count()}\n{s}");
    }
}

 

1
krum_43 avatar krum_43 750 Точки

Това на практика е същото решение в съкратен и сбит вариант.

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.