Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace Problem_2._Emoji_Detector_FinalExam_04._04._20
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- string pattern = @"(::|\*\*)(?<emoji>[A-Z][a-z]{2,})\1";
- string pattDigits = @"\d";
- MatchCollection matchesDigits = Regex.Matches(input, pattDigits);
- decimal coolThreshold = 1;
- foreach (Match digit in matchesDigits)
- {
- coolThreshold *= decimal.Parse(digit.Value);
- }
- MatchCollection matchesEmojies = Regex.Matches(input, pattern);
- List<string> coolEmojis = new List<string>();
- foreach (Match emoji in matchesEmojies)
- {
- string currentEmoji = emoji.Groups["emoji"].Value;
- decimal currSum = 0;
- for (int i = 0; i < currentEmoji.Length; i++)
- {
- char currentLet = currentEmoji[i];
- currSum += (decimal)(currentLet);
- }
- if (coolThreshold <= currSum)
- {
- coolEmojis.Add(emoji.Value);
- }
- }
- int countOfEmojies = matchesEmojies.Count;
- Console.WriteLine($"Cool threshold: {coolThreshold}");
- Console.WriteLine($"{countOfEmojies} emojis found in the text. The cool ones are:");
- foreach (string emoji in coolEmojis)
- {
- Console.WriteLine(emoji);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment