Guest User

Untitled

a guest
Apr 2nd, 2021
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace _2._Emoji_Detector
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string digitPattern = @"[2-9]";
  12. string emojiPattern = @"((::)|(\*\*))([A-Z][a-z]{2,})\1";
  13. ulong threshold = 1;
  14. ulong emojiSum = 0;
  15.  
  16. List<string> result = new List<string>();
  17.  
  18. string text = Console.ReadLine();
  19.  
  20. Regex regDigit = new Regex(digitPattern);
  21. Regex regEmoj = new Regex(emojiPattern);
  22.  
  23. var matchRegDigit = regDigit.Matches(text);
  24. var matchRegEmoj = regEmoj.Matches(text);
  25.  
  26. int emojiCount = matchRegEmoj.Count;
  27.  
  28. foreach (Match item in matchRegDigit)
  29. {
  30. ulong digit = ulong.Parse(item.Groups[0].Value);
  31. threshold = threshold * digit;
  32. }
  33.  
  34. foreach (Match item in matchRegEmoj)
  35. {
  36. string emoji = item.Groups[4].Value;
  37. string fullEmoji = item.Groups[0].Value;
  38.  
  39. for (int i = 0; i < emoji.Length; i++)
  40. {
  41. emojiSum += emoji[i];
  42. }
  43.  
  44. if (emojiSum > threshold)
  45. {
  46. result.Add(fullEmoji);
  47. }
  48. emojiSum = 0;
  49. }
  50.  
  51. Console.WriteLine($"Cool threshold: {threshold}");
  52. Console.WriteLine($"{emojiCount} emojis found in the text. The cool ones are:");
  53.  
  54. foreach (var item in result)
  55. {
  56. Console.WriteLine(item);
  57. }
  58. }
  59. }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment