Advertisement
bullit3189

EmojiSumator-StringAndRegex

Apr 9th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Text;
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. string msg = Console.ReadLine();
  12. int[] codeTokens = Console.ReadLine().Split(':').Select(int.Parse).ToArray();
  13.  
  14. List<string>emojis = new List<string>();
  15.  
  16.  
  17. string emojiCode = string.Empty;
  18.  
  19. for (int i=0; i<codeTokens.Length; i++)
  20. {
  21. int currNum = codeTokens[i];
  22. char toAdd = (char)currNum;
  23. emojiCode+= toAdd;
  24. }
  25.  
  26. if (emojiCode != string.Empty)
  27. {
  28. emojiCode = emojiCode.Insert(0,":");
  29. emojiCode += ":";
  30. }
  31.  
  32. string pattern = @"(?<=\s):[a-z]{4,}:(?=\s|,|\.|!|\?)";
  33.  
  34. if (Regex.IsMatch(msg,pattern))
  35. {
  36. MatchCollection matches = Regex.Matches(msg,pattern);
  37.  
  38. foreach (Match match in matches)
  39. {
  40. emojis.Add(match.Value);
  41. }
  42. }
  43.  
  44. int totalPower = 0;
  45.  
  46. foreach (string emoji in emojis)
  47. {
  48. for (int i=0; i<emoji.Length; i++)
  49. {
  50. char curr = emoji[i];
  51. if (char.IsLower(curr))
  52. {
  53. int asNum = (int)curr;
  54. totalPower += asNum;
  55. }
  56. }
  57. }
  58.  
  59. foreach (string emoji in emojis)
  60. {
  61. if (emoji == emojiCode)
  62. {
  63. totalPower *=2;
  64. }
  65. }
  66.  
  67. if (emojis.Count!=0)
  68. {
  69. Console.WriteLine("Emojis found: " + string.Join(", ",emojis));
  70. }
  71.  
  72. Console.WriteLine("Total Emoji Power: {0}",totalPower);
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement