Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5.  
  6. namespace EmojiDetector
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string text = Console.ReadLine();
  13.             Regex emojies = new Regex(@"([\*][\*]|[\:][\:])(?<emoji>[A-Z][a-z]{2,})\1");
  14.             Regex numbers = new Regex(@"\d");
  15.             List<string> coolThreshold = new List<string>();
  16.             long numberResult = 1;
  17.             MatchCollection validEmoji = emojies.Matches(text);
  18.             MatchCollection validNumbers = numbers.Matches(text);
  19.             foreach (Match number in validNumbers)
  20.             {
  21.                 long currNumber = long.Parse(number.ToString());
  22.                 numberResult *= currNumber;
  23.             }
  24.  
  25.             foreach (Match emoji in validEmoji)
  26.             {
  27.                 string currEmoji = emoji.Groups["emoji"].Value;
  28.                 long emojiResult = 0;
  29.                 for (int i = 0; i < currEmoji.Length; i++)
  30.                 {                    
  31.                     int asciiValue = currEmoji[i];
  32.                     emojiResult += asciiValue;  
  33.                 }
  34.                 if (emojiResult >= numberResult)
  35.                 {
  36.                     coolThreshold.Add(emoji.ToString());
  37.                 }
  38.             }
  39.             Console.WriteLine($"Cool threshold: {numberResult}");
  40.             Console.WriteLine($"{validEmoji.Count} emojis found in the text. The cool ones are:");
  41.             Console.WriteLine($"{string.Join(" \n", coolThreshold)}");
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement