Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace _02._Emoji_Detector
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string pattern = @"(::|\*\*)(?<emoji>[A-Z][a-z]{2,})\1";
  12.             string text = Console.ReadLine();
  13.             MatchCollection matches = Regex.Matches(text, pattern);
  14.             long coolThreshold = 1;
  15.             List<string> cool = new List<string>();
  16.             for (int i = 0; i < text.Length; i++)
  17.             {
  18.                 if (char.IsDigit(text[i]))
  19.                 {
  20.                     string currentDigit = text[i].ToString();
  21.                     int digit = int.Parse(currentDigit);
  22.                     coolThreshold *= digit;
  23.                 }
  24.             }
  25.            
  26.             for (int i = 0; i < matches.Count; i++)
  27.             {
  28.                 int coolness = 0;
  29.                 string currentMatch = matches[i].Groups["emoji"].Value;
  30.                 for (int j = 0; j < currentMatch.Length; j++)
  31.                 {
  32.                     coolness += currentMatch[j];
  33.                 }
  34.                 if (coolness > coolThreshold)
  35.                 {
  36.                     cool.Add(matches[i].Value);
  37.                 }
  38.             }
  39.             Console.WriteLine($"Cool threshold: {coolThreshold}");
  40.             Console.WriteLine($"{matches.Count} emojis found in the text. The cool ones are:");
  41.             if (cool.Count > 0)
  42.             {
  43.                 foreach (var item in cool)
  44.                 {
  45.                     Console.WriteLine(item);
  46.                 }
  47.             }
  48.            
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement