Advertisement
Guest User

Emoji Sumator

a guest
Dec 3rd, 2019
1,026
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Demo
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string patternTwo = @"(?<=[\s])\:(?<emoji>[a-z]{4,})\:(?=[\s,.!?])";
  13.  
  14.             List<string> emojis = new List<string>();
  15.             List<string> emojisForPrint = new List<string>();
  16.  
  17.             string input = Console.ReadLine();
  18.  
  19.             List<int> emojiCode = Console.ReadLine().Split(":").Select(int.Parse).ToList();
  20.  
  21.             MatchCollection matchedEmojis = Regex.Matches(input, patternTwo);
  22.  
  23.             foreach (Match emoji in matchedEmojis)
  24.             {
  25.                 string text = emoji.Groups["emoji"].Value;
  26.  
  27.                 if (IsAllCharEnglish(text))
  28.                 {
  29.                     emojis.Add(emoji.Groups["emoji"].Value);
  30.  
  31.                     emojisForPrint.Add($":{emoji.Groups["emoji"].Value}:");
  32.                 }
  33.             }
  34.  
  35.             int emojiPower = SummingTheASCIIValuesFromEmojiLetters(emojis);
  36.  
  37.             string emojiName = string.Empty;
  38.  
  39.             for (int i = 0; i < emojiCode.Count; i++)
  40.             {
  41.                 emojiName += ((char)emojiCode[i]).ToString();
  42.             }
  43.  
  44.             if (emojisForPrint.Count == 0)
  45.             {
  46.                 Console.WriteLine("Total Emoji Power: 0");
  47.                 return;
  48.             }
  49.  
  50.             if (emojis.Contains(emojiName))
  51.             {
  52.                 emojiPower *= 2;
  53.  
  54.                 Console.WriteLine($"Emojis found: {string.Join(", ", emojisForPrint)}");
  55.                 Console.WriteLine($"Total Emoji Power: {emojiPower}");
  56.             }
  57.             else
  58.             {
  59.                 Console.WriteLine($"Emojis found: {string.Join(", ", emojisForPrint)}");
  60.                 Console.WriteLine($"Total Emoji Power: {emojiPower}");
  61.             }
  62.  
  63.         }
  64.  
  65.         private static int SummingTheASCIIValuesFromEmojiLetters(List<string> emojis)
  66.         {
  67.             int totalSum = 0;
  68.  
  69.             for (int i = 0; i < emojis.Count; i++)
  70.             {
  71.                 string currentEmoji = emojis[i];
  72.  
  73.                 for (int j = 0; j < currentEmoji.Length; j++)
  74.                 {
  75.                     totalSum += currentEmoji[j];
  76.                 }
  77.             }
  78.  
  79.             return totalSum;
  80.         }
  81.  
  82.         public static bool IsAllCharEnglish(string Input)
  83.         {
  84.             foreach (var item in Input.ToCharArray())
  85.             {
  86.                 if (!char.IsLower(item) && !char.IsUpper(item) && !char.IsDigit(item) && !char.IsWhiteSpace(item))
  87.                 {
  88.                     return false;
  89.                 }
  90.             }
  91.  
  92.             return true;
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement