elena1234

EmojiDetector -ExamPreparation

Dec 4th, 2020 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Numerics;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace EmojiDetector
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string input = Console.ReadLine();
  13.             var listCoolEmojies = new List<string>();
  14.             Regex regexForThreshold = new Regex(@"[0-9]");
  15.             MatchCollection matchesForThreshold = regexForThreshold.Matches(input);
  16.             BigInteger threshold = 1;
  17.             foreach (Match match in matchesForThreshold)
  18.             {
  19.                 string matchString= (match.Value);
  20.                 int number = int.Parse(matchString);
  21.                 threshold = threshold * number;
  22.             }
  23.  
  24.             Regex regexForEmojies = new Regex(@"(::|\*\*)(?<emoji>[A-Z][a-z]{2,})\1");
  25.             MatchCollection matchesValidEmojies = regexForEmojies.Matches(input);
  26.             foreach (Match match in matchesValidEmojies )
  27.             {
  28.                 string validEmoji = match.Value;
  29.                 string validEmojiOnlyLetter = match.Groups["emoji"].Value;
  30.                 int sumASCII = 0;
  31.                 for (int i = 0; i < validEmojiOnlyLetter.Length; i++)
  32.                 {
  33.                     sumASCII += validEmojiOnlyLetter[i];
  34.                 }
  35.  
  36.                 if(sumASCII > threshold)
  37.                 {
  38.                     listCoolEmojies.Add(validEmoji);
  39.                 }
  40.             }
  41.  
  42.             Console.WriteLine($"Cool threshold: {threshold}");
  43.             Console.WriteLine($"{matchesValidEmojies.Count} emojis found in the text. The cool ones are: ");
  44.             Console.WriteLine(string.Join(Environment.NewLine,listCoolEmojies));
  45.         }
  46.     }
  47. }
  48.  
Add Comment
Please, Sign In to add comment