petaryankov00

EmojiDetector

Dec 4th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace EmojiDetector
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.             string emojiPattern = @"(\:{2}|\*{2})([A-Z]{1}[a-z]{2,})\1";            
  13.             string digitPattern = @"\d";        
  14.  
  15.             List<string> emojies = new List<string>();
  16.             MatchCollection digits = Regex.Matches(input, digitPattern);
  17.             List<string> coolOnes = new List<string>();
  18.  
  19.             int threshold = 1;          
  20.             foreach (Match currDigit in digits)
  21.             {
  22.                 int digit = int.Parse(currDigit.Value);
  23.                 threshold *= digit;
  24.             }
  25.             MatchCollection emojiMatches = Regex.Matches(input, emojiPattern);
  26.             foreach (Match emoji in emojiMatches)
  27.             {
  28.                 string currEmoji = emoji.Value.ToString();
  29.                 emojies.Add(currEmoji);
  30.             }
  31.             int emojiesFound = emojies.Count;
  32.             for (int i = 0; i < emojies.Count; i++)
  33.             {
  34.                 string currEmoji = emojies[i];
  35.                 char[] currLetters = emojies[i].ToCharArray();
  36.                 long sum = 0;
  37.                 for (int j = 0; j < currLetters.Length; j++)
  38.                 {
  39.                     char currLetter = currLetters[j];
  40.                     sum += (long)(currLetter);
  41.                 }
  42.                 if (sum > threshold)
  43.                 {
  44.                     coolOnes.Add(currEmoji);
  45.                 }
  46.             }
  47.             Console.WriteLine($"Cool threshold: {threshold}");          
  48.             Console.WriteLine($"{emojiesFound} emojis found in the text. The cool ones are:");
  49.             foreach (var item in coolOnes)
  50.             {
  51.                 Console.WriteLine(item);
  52.             }
  53.         }
  54.     }
  55. }
  56.  
Add Comment
Please, Sign In to add comment