Advertisement
Guest User

Emoji Detector

a guest
Apr 6th, 2020
1,767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6.  
  7. namespace Emoji_Detector
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Regex validator = new Regex(@"([:]{2}|[*]{2})(?<name>[A-Z][a-z]{2,})\1");
  14.             Regex coolThresholdValidator = new Regex(@"\d");
  15.             List<string> coolEmojis = new List<string>();
  16.             int coolThreshold = 0;
  17.             int sumEmoji = 0;
  18.             int emojisInText = 0;
  19.             string input = Console.ReadLine();
  20.             if (validator.IsMatch(input) || coolThresholdValidator.IsMatch(input))
  21.             {
  22.                 MatchCollection matchesThreshold = coolThresholdValidator.Matches(input);
  23.                 var matchesToArr = matchesThreshold.Select(v => int.Parse(v.Value)).ToArray();
  24.                 coolThreshold = matchesToArr.Aggregate(1, (a, b) => a * b);
  25.                 MatchCollection emojis = validator.Matches(input);
  26.                 emojisInText += emojis.Count;
  27.                 foreach (Match emoji in emojis)
  28.                 {
  29.  
  30.                     string emojiToString = emoji.Groups["name"].Value;
  31.                     for (int curr = 0; curr < emojiToString.Length; curr++)
  32.                     {
  33.                         if (char.IsLetter(emojiToString[curr]))
  34.                         {
  35.                             sumEmoji += emojiToString[curr];
  36.                         }
  37.                     }
  38.                     if (sumEmoji > coolThreshold)
  39.                     {
  40.                         coolEmojis.Add(emoji.Value);
  41.                     }
  42.                     sumEmoji = 0;
  43.                 }
  44.             }
  45.             Console.WriteLine($"Cool threshold: {coolThreshold}");
  46.             Console.WriteLine($"{emojisInText} emojis found in the text. The cool ones are:");
  47.             foreach (string emoji in coolEmojis)
  48.             {
  49.                 Console.WriteLine(emoji);
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement