Advertisement
parunowaa

02.Emoji_Detector

Dec 11th, 2021
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Numerics;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace _02.Emoji_Detector
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.  
  15.             //emoji matches:
  16.             string regex = @"(::|\*\*)(?<emojis>[A-Z][a-z]{2,})(\1)";
  17.             MatchCollection matches = Regex.Matches(input, regex);
  18.  
  19.             //numbers matches:
  20.             Regex numRegex = new Regex(@"\d");
  21.             MatchCollection numMatches = numRegex.Matches(input);
  22.  
  23.             int coolTreshold = 1;
  24.             foreach (Match numMatch in numMatches)
  25.             {
  26.                 coolTreshold *= int.Parse(numMatch.Value);
  27.             }
  28.  
  29.             Console.WriteLine($"Cool threshold: {coolTreshold}");
  30.             int emojiCharSum = 0;
  31.             int emojiCount = 0;
  32.             foreach (Match match in matches)
  33.             {
  34.                 emojiCount++;
  35.             }
  36.             Console.WriteLine($"{emojiCount} emojis found in the text. The cool ones are:");
  37.  
  38.             foreach (Match match in matches)
  39.             {
  40.                 var charValues = Encoding.ASCII.GetBytes(match.Groups["emojis"].Value);
  41.                 foreach (var charVal in charValues)
  42.                 {
  43.                     emojiCharSum += charVal;
  44.                 }
  45.  
  46.                 if (coolTreshold < emojiCharSum)
  47.                 {
  48.                     Console.WriteLine(match.Value);
  49.                 }
  50.  
  51.                 emojiCharSum = 0;
  52.             }
  53.         }
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement