Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. namespace Regex
  2. {
  3.     using System;
  4.     using System.Text.RegularExpressions;
  5.     using System.Collections.Generic;
  6.     using System.Linq;
  7.  
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string input = Console.ReadLine();
  13.             Regex regex = new Regex(@"([:|*]{2})(?<emoji>[A-Z][a-z]{2,})\1");
  14.             MatchCollection result = regex.Matches(input);
  15.  
  16.             List<string> coolEmoji = new List<string>();
  17.  
  18.             foreach (Match item in result)
  19.             {
  20.                 coolEmoji.Add(item.ToString());
  21.             }
  22.  
  23.             Regex digit = new Regex("[0-9]");
  24.             MatchCollection totoalDigit = digit.Matches(input);
  25.             long thresHoldSum = 1;
  26.             foreach (var d in totoalDigit)
  27.             {
  28.                 thresHoldSum *= int.Parse(d.ToString());
  29.             }
  30.  
  31.             var badEmojis = new List<string>();
  32.  
  33.             foreach (var item in coolEmoji)
  34.             {
  35.                 int sum = 0;
  36.                 string tempItem = item;
  37.  
  38.                 tempItem.Trim(':');
  39.                 tempItem.Trim('*');
  40.  
  41.                 foreach (var letter in tempItem) sum += letter;
  42.  
  43.                 if (sum < thresHoldSum)
  44.                 {
  45.                     badEmojis.Add(item);
  46.                 }
  47.             }
  48.  
  49.             coolEmoji = coolEmoji.Where(x => !badEmojis.Contains(x)).ToList();
  50.  
  51.             Console.WriteLine($"Cool threshold: {thresHoldSum}");
  52.  
  53.             Console.WriteLine($"{result.Count} emojis found in the text. The cool ones are:");
  54.             foreach (var emoji in coolEmoji)
  55.             {
  56.                 Console.WriteLine($"{emoji}");
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement