Advertisement
dragonbs

Emoji Detector

Mar 27th, 2023
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Numerics;
  4. using System.Text.RegularExpressions;
  5.  
  6. class Program
  7. {
  8.     static void Main()
  9.     {
  10.         string input = Console.ReadLine();
  11.         MatchCollection digits = Regex.Matches(input, @"\d");
  12.         MatchCollection emojis = Regex.Matches(input, @"([:*])\1[A-Z][a-z]{2,}\1\1");
  13.  
  14.         BigInteger coolThreshold = new BigInteger(1);
  15.         foreach (Match digit in digits)
  16.             coolThreshold *= int.Parse(digit.Value);
  17.  
  18.         List<string> coolEmojis = new List<string>();
  19.         foreach (Match emoji in emojis)
  20.         {
  21.             string emojiString = emoji.Value;
  22.             int emojiValue = 0;
  23.             for (int i = 0; i < emoji.Value.Length; i++)
  24.             {
  25.                 if (char.IsLetter(emojiString[i]))
  26.                     emojiValue += (int)emojiString[i];
  27.             }
  28.             if (emojiValue > coolThreshold)
  29.                 coolEmojis.Add(emojiString);
  30.         }
  31.  
  32.         Console.WriteLine($"Cool threshold: {coolThreshold}");
  33.         Console.WriteLine($"{emojis.Count} emojis found in the text. The cool ones are:");
  34.         Console.WriteLine(String.Join("\n", coolEmojis));
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement