alexbancheva

Problem_2._Emoji_Detector_FinalExam_04._04._20

Apr 4th, 2020
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Problem_2._Emoji_Detector_FinalExam_04._04._20
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.  
  13.            
  14.             string input = Console.ReadLine();
  15.             string pattern = @"(::|\*\*)(?<emoji>[A-Z][a-z]{2,})\1";
  16.  
  17.             string pattDigits = @"\d";
  18.             MatchCollection matchesDigits = Regex.Matches(input, pattDigits);
  19.          
  20.  
  21.             decimal coolThreshold = 1;
  22.  
  23.             foreach (Match digit in matchesDigits)
  24.             {
  25.                 coolThreshold *= decimal.Parse(digit.Value);
  26.             }
  27.            
  28.             MatchCollection matchesEmojies = Regex.Matches(input, pattern);
  29.  
  30.             List<string> coolEmojis = new List<string>();
  31.  
  32.             foreach (Match emoji in matchesEmojies)
  33.             {
  34.  
  35.                 string currentEmoji = emoji.Groups["emoji"].Value;
  36.                 decimal currSum = 0;
  37.  
  38.                 for (int i = 0; i < currentEmoji.Length; i++)
  39.                 {
  40.                     char currentLet = currentEmoji[i];
  41.                     currSum += (decimal)(currentLet);
  42.                 }
  43.  
  44.                 if (coolThreshold <= currSum)
  45.                 {
  46.                     coolEmojis.Add(emoji.Value);
  47.  
  48.                 }
  49.  
  50.             }
  51.             int countOfEmojies = matchesEmojies.Count;
  52.  
  53.             Console.WriteLine($"Cool threshold: {coolThreshold}");
  54.             Console.WriteLine($"{countOfEmojies} emojis found in the text. The cool ones are:");
  55.             foreach (string emoji in coolEmojis)
  56.             {
  57.                 Console.WriteLine(emoji);
  58.             }
  59.  
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment