+ Нов въпрос
razihanna avatar razihanna 7 Точки

C# Fundamentals 02. Emoji Detector


I got 80/100 in Judge for this problem, could you please assist to find what is the mistake?

Thank you

My code

using System;using System.Collections.Generic;using System.Text.RegularExpre - Pastebin.com



05. Programming Fundamentals Final Exam - SoftUni Judge

Programming Fundamentals Final Exam 04.04.2020

Problem 2. Emoji Detector

Your task is to write program which extracts emojis from a text and find the threshold based on the input.

You have to get your cool threshold. It is obtained by multiplying all the digits found in the input.  The cool threshold could be a very big number, so be mindful.

An emoji is valid when:

  • Is surrounded by either :: or ** (exactly 2)
  • Is at least 3 characters long (without the surrounding symbols)
  • Starts with a capital letter
  • Continues with lowercase letters only

Examples of valid emojis: ::Joy::, **Banana**, ::Wink::

Examples of invalid emojis: ::Joy**, ::fox:es:, **Monk3ys**, :Snak::Es::

You need to count all valid emojis in the text and calculate their coolness. The coolness of the emoji is determined by summing all the ASCII values of all letters in the emoji.

Examples: ::Joy:: - 306, **Banana** - 577, ::Wink:: - 409

You need to print the result of cool threshold and after that to take all emojis out of the text, count them and print the only the cool ones on the console.


  • On the single input you will receive a piece of string.


  • On the first line of the output print the obtained Cool threshold in format:
  • Cool threshold: {coolThresholdSum}

On the next line print the count of all emojis found in the text in format:

  • {countOfAllEmojis} emojis found in the text. The cool ones are:
  • {cool emoji 1}
  • {cool emoji 2}
  • {…}

If there are no cool ones, just don't print anything in the end.


There will always be at least one digit in the text!




In the Sofia Zoo there are 311 animals in total! ::Smiley:: This includes 3 **Tigers**, 1 ::Elephant:, 12 **Monk3ys**, a **Gorilla::, 5 ::fox:es: and 21 different types of :Snak::Es::. ::Mooning:: **Shy**

Cool threshold: 540

4 emojis found in the text. The cool ones are:





You can see all the valid emojis in green. There are various reasons why the rest are not valid, examine them carefully. The "cool threshold" is 3*1*1*3*1*1*2*3*5*2*1 = 540.

::Smiley:: -> 83 + 109 + 105 + 108 + 101 + 121 = 627 > 540 -> cool

**Tigers** -> 84 + 105 + 103 + 101 + 114 + 115 = 622 > 540 -> cool

::Mooning:: -> 77 + 111 + 111 + 110 + 105 + 110 + 103 = 727 > 540 -> cool

**Shy** -> 83 + 104 + 121 = 308 < 540 -> not cool

At the end we print the count of all valid emojis found and each of the cool ones on a new line.



5, 4, 3, 2, 1, go! The 1-th consecutive banana-eating contest has begun! ::Joy:: **Banana** ::Wink:: **Vali** ::valid_emoji::

Cool threshold: 120

4 emojis found in the text. The cool ones are:







It is a long established fact that 1 a reader will be distracted by 9 the readable content of a page when looking at its layout. The point of using ::LoremIpsum:: is that it has a more-or-less normal 3 distribution of 8 letters, as opposed to using 'Content here, content 99 here', making it look like readable **English**.

Cool threshold: 17496

1 emojis found in the text. The cool ones are:


You can see **English** is a valid emoji, but the sum of ascii is not bigger than cool threshold, that's why we don't print anything in the end.




Fundamentals Module
Axiomatik avatar Axiomatik 2399 Точки
Best Answer

Check your number-Regex and your final output lines when there are no emojis found in the given text (should only print one line in this case), otherwise looks OK.


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

namespace emoji
    class Program
        static void Main(string[] args)
            string numberPattern = @"(?<number>[0-9])";
            string emojiPattern = @"(:{2}|\*{2})(?<emoji>[A-Z][a-z]{2,})\1";

            Regex numberRegex = new Regex(numberPattern);
            Regex emojiRegex = new Regex(emojiPattern);

            string input = Console.ReadLine();

            MatchCollection numberMatches = numberRegex.Matches(input);

            MatchCollection emojiMatches = emojiRegex.Matches(input);

            var numbers = new List<int>();

            foreach (Match match in numberMatches)
                int number = int.Parse(match.ToString());


            int coolTotal = 0;

            if (numbers.Count >= 2)
                for (int i = 0; i < numbers.Count; i++)
                    if (i == 0)
                        coolTotal += numbers[i] * numbers[i + 1];
                        coolTotal *= numbers[i];
                coolTotal = numbers.Sum();

            var emojiList = new Dictionary<string, int>();

            foreach (Match match in emojiMatches)
                string emoji = match.Groups["emoji"].ToString();
                char[] letters = emoji.ToCharArray();
                int number = letters.Sum(x => (int)x);
                string trueEmoji = match.ToString();

                if (!emojiList.ContainsKey(trueEmoji))
                    emojiList.Add(trueEmoji, number);

            Console.WriteLine($"Cool threshold: {coolTotal}");

            if (emojiList.Any())
                Console.WriteLine($"{emojiList.Count} emojis found in the text. The cool ones are:");
                foreach (var (name, number) in emojiList)
                    if (number > coolTotal)


02/04/2021 12:23:00
razihanna avatar razihanna 7 Точки

Thank you very much. Appreciate your reply , now I got 100%

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