Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5. using System.Collections.Generic;
  6. using System.Numerics;
  7.  
  8. namespace _02._Emoji_Detector
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var text = Console.ReadLine();
  15.             var emojiRegex = new Regex(@"(::|\*\*)(?<Emoji>[A-Z][a-z]{2,})\1");
  16.             var coolRegex = new Regex(@"\d");
  17.             var numbers = new List<int>();
  18.             long sumRequired = 1;
  19.             var matches = coolRegex.Matches(text);
  20.  
  21.             foreach (Match match in matches)
  22.             {
  23.                 numbers.Add(int.Parse(match.Value));
  24.             }
  25.             for (int i = 0; i < numbers.Count; i++)
  26.             {
  27.                 sumRequired *= numbers[i];
  28.             }
  29.  
  30.             Console.WriteLine($"Cool threshold: {sumRequired}");
  31.  
  32.             matches = emojiRegex.Matches(text);
  33.             var emojies = new List<string>();
  34.             var fullMatches = new List<string>();
  35.  
  36.             foreach (Match match in matches)
  37.             {
  38.                 var currentEmoji = match.Groups["Emoji"].Value;
  39.                 var currentSymbol = match.Groups[1].Value;
  40.                 fullMatches.Add(currentSymbol + currentEmoji + currentSymbol);
  41.                 emojies.Add(currentEmoji);
  42.             }
  43.  
  44.             if (emojies.Count>0)
  45.             {
  46.  
  47.                 Console.WriteLine($"{fullMatches.Count} emojis found in the text. The cool ones are:");
  48.  
  49.                 foreach (var item in emojies)
  50.                 {
  51.                     var sum = GetSumOfChars(item);
  52.  
  53.                     if (sum < sumRequired)
  54.                     {
  55.                         var index = emojies.IndexOf(item);
  56.                         fullMatches.RemoveAt(index);
  57.                     }
  58.                 }
  59.             }
  60.            
  61.             if (fullMatches.Count>0)
  62.             {
  63.                 foreach (var item in fullMatches)
  64.                 {
  65.                     Console.WriteLine(item);
  66.                 }
  67.             }
  68.            
  69.         }
  70.  
  71.         static int GetSumOfChars(string emoji)
  72.         {
  73.             var sum = 0;
  74.             for (int i = 0; i < emoji.Length; i++)
  75.             {
  76.                 var currentChar = (int)emoji[i];
  77.                 sum += currentChar;
  78.             }
  79.  
  80.             return sum;
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement