Advertisement
Guest User

regex

a guest
Apr 4th, 2020
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 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.     using System.Text;
  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.             List<string> coolEmoji = new List<string>();
  16.             foreach (var emoji in result)
  17.             {
  18.                 coolEmoji.Add(emoji.ToString());
  19.             }
  20.             Regex digit = new Regex("[0-9]");
  21.             MatchCollection totoalDigit = digit.Matches(input);
  22.             List<string> totalSum = new List<string>();
  23.             foreach (var d in totoalDigit)
  24.             {
  25.                 totalSum.Add(d.ToString());
  26.             }
  27.  
  28.             long thresHoldSum = 1;
  29.             for (int i = 0; i < totalSum.Count; i++)
  30.             {
  31.                 long currDig = long.Parse(totalSum[i]);
  32.                 thresHoldSum *= currDig;
  33.             }
  34.  
  35.             for (int i = 0; i < coolEmoji.Count; i++)
  36.             {
  37.                 long emojiSum = 0;
  38.                 string currEmoji = coolEmoji[i];
  39.                 for (int u = 0; u < currEmoji.Length; u++)
  40.                 {
  41.                     if (currEmoji[u] != '*' && currEmoji[u] != ':')
  42.                     {
  43.                         emojiSum += currEmoji[u];
  44.                     }
  45.                 }
  46.                 if (emojiSum < thresHoldSum)
  47.                 {
  48.                     coolEmoji.Remove(currEmoji);
  49.                 }
  50.             }
  51.  
  52.             Console.WriteLine($"Cool threshold: {thresHoldSum}");
  53.  
  54.             if (coolEmoji.Count > 0)
  55.             {
  56.                 Console.WriteLine($"{result.Count} emojis found in the text. The cool ones are:");
  57.                 foreach (var emoji in coolEmoji)
  58.                 {
  59.                     Console.WriteLine($"{emoji}");
  60.                 }
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement