Guest User

Untitled

a guest
Aug 4th, 2021
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace EmojiDetector
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string text = Console.ReadLine();
  13.  
  14. Dictionary<string, int> dictionary = new Dictionary<string, int>();
  15.  
  16. long thresHold = 1;
  17.  
  18. for (int i = 0; i < text.Length; i++)
  19. {
  20. if (char.IsDigit(text[i]))
  21. {
  22. thresHold *= int.Parse(text[i].ToString());
  23. }
  24. }
  25.  
  26.  
  27. string emojiPattern = @"([*|:]{2})(?<letters>[A-Z][a-z]{2,})\1";
  28.  
  29. MatchCollection emojies = Regex.Matches(text, emojiPattern);
  30.  
  31. int coolness = 0;
  32.  
  33. for (int i = 0; i < emojies.Count; i++)
  34. {
  35. string emoji = emojies[i].Groups["letters"].Value;
  36.  
  37. for (int j = 0; j < emoji.Length; j++)
  38. {
  39. coolness += emoji[j];
  40. }
  41.  
  42. if (!dictionary.ContainsKey(emojies[i].Value))
  43. {
  44. dictionary.Add(emojies[i].Value, coolness);
  45.  
  46. }
  47. coolness = 0;
  48. }
  49.  
  50. int countTotalEmojies = dictionary.Count;
  51.  
  52. dictionary = dictionary.Where(x => x.Value > thresHold).ToDictionary(x => x.Key, x => x.Value);
  53.  
  54. Console.WriteLine($"Cool threshold: {thresHold}");
  55. Console.WriteLine($"{countTotalEmojies} emojis found in the text. The cool ones are:");
  56. foreach (var item in dictionary)
  57. {
  58. Console.WriteLine(item.Key);
  59. }
  60.  
  61.  
  62. }
  63. }
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment