Loading...

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

petaryankov00 avatar petaryankov00 3 Точки

02.EmojiDetector

  Здравейте, имам проблем с една от задачите от Programming Fundamentals Final Exam - 04 April 2020 Group 1.

Judge ми дава 80/100 и не мога да разбера къде ми е грешката. Ще съм благодарен, ако някой може да помогне.

Моето решение: https://pastebin.com/fv3AeHTY

Условието: 

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.

Input

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

Output

  • 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.

0
Fundamentals Module
Axiomatik avatar Axiomatik 2422 Точки

Had the same problem with 80%, I think the issue was the way how you calculate the 'cool treshold' and specifically for the case there was just one digit. Here two variants with 80% and 100%:

(80%):

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());

                numbers.Add(number);
            }

            int coolTotal = 0;
            
            for (int i = 0; i < numbers.Count; i++)
            {
                if (i == 0)
                {
                    coolTotal += numbers[i] * numbers[i + 1];
                    i++;
                }
                else
                {
                    coolTotal *= numbers[i];
                }
            }

            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)
                    {
                        Console.WriteLine($"{name}");
                    }
                }
            }
        }
    }
}

(100%):

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());

                numbers.Add(number);
            }

            int coolTotal = 0;

            if (numbers.Count >= 2)
            {
                for (int i = 0; i < numbers.Count; i++)
                {
                    if (i == 0)
                    {
                        coolTotal += numbers[i] * numbers[i + 1];
                        i++;
                    }
                    else
                    {
                        coolTotal *= numbers[i];
                    }
                }
            }
            else
            {
                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)
                    {
                        Console.WriteLine($"{name}");
                    }
                }
            }
        }
    }
}

 

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