Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. namespace _02._Emoji_Detector
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class EmojiDetector
  8. {
  9. public static void Main()
  10. {
  11. string pattern = @"(:{2}|\*{2})(?<emojiName>[A-Z][a-z]{2,})\1";
  12. string digitPattern = @"\d";
  13.  
  14. string inputText = Console.ReadLine();
  15.  
  16. List<string> coolEmojis = new List<string>();
  17. long coolThresholdSum = 1;
  18. int countOfAllEmojis = 0;
  19.  
  20. MatchCollection matches = Regex.Matches(inputText, pattern);
  21. MatchCollection digitMatches = Regex.Matches(inputText, digitPattern);
  22.  
  23. foreach (Match digit in digitMatches)
  24. {
  25. coolThresholdSum *= int.Parse(digit.Value);
  26. }
  27.  
  28. foreach (Match match in matches)
  29. {
  30. string name = match.Groups["emojiName"].Value;
  31. int sumNameAsDigits = 0;
  32. countOfAllEmojis++;
  33.  
  34. for (int i = 0; i < name.Length; i++)
  35. {
  36. char currentChar = name[i];
  37. sumNameAsDigits += currentChar;
  38. }
  39.  
  40. if (sumNameAsDigits > coolThresholdSum)
  41. {
  42. coolEmojis.Add(match.Value);
  43. }
  44. else
  45. {
  46. continue;
  47. }
  48. }
  49.  
  50. Console.WriteLine($"Cool threshold: {coolThresholdSum}");
  51. Console.WriteLine($"{countOfAllEmojis} emojis found in the text. The cool ones are:");
  52. Console.WriteLine(string.Join("\n", coolEmojis));
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement