Advertisement
Guest User

Untitled

a guest
Aug 5th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _2._Emoji_Detector
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string text = Console.ReadLine();
  13.             var coolEmojis = new List<string>();
  14.             string firstPattern = @"(?<numbers>[\d])";
  15.             string secondPattern = @"([:*]{2})(?<emojiName>[A-Z][a-z]{2,})\1";
  16.             int result = 1;
  17.             MatchCollection matchedNums = Regex.Matches(text, firstPattern);
  18.             foreach (Match match in matchedNums)
  19.             {
  20.                 result *= int.Parse(match.Value);
  21.             }
  22.             MatchCollection matchedEmojis = Regex.Matches(text, secondPattern);
  23.             int emojisCount = 0;
  24.             int singleEmojisum = 0;
  25.  
  26.  
  27.             Console.WriteLine($"Cool threshold: {result}");
  28.             foreach (Match match in matchedEmojis)
  29.             {
  30.                 emojisCount++;
  31.             }
  32.            
  33.             foreach (Match match in matchedEmojis)
  34.             {
  35.  
  36.                 for (int i = 0; i < match.Length; i++)
  37.                 {
  38.  
  39.                     singleEmojisum += (int)match.Value[i];
  40.                 }
  41.                
  42.                 if (singleEmojisum > result)
  43.                 {
  44.                     coolEmojis.Add(match.Value);
  45.                 }
  46.                
  47.                 singleEmojisum = 0;
  48.             }
  49.             Console.WriteLine($"{emojisCount} emojis found in the text. The cool ones are: ");
  50.             Console.WriteLine(String.Join(Environment.NewLine, coolEmojis));
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement