Advertisement
Ivan_konov

Emoji Sumator

Jul 21st, 2019
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Emoji_Sumator
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Regex regex = new Regex(@"(?<=[\s])(?<emoji>:[a-z]{4,}:)(?=[\s,.!?])");
  13.             string givenMessage = Console.ReadLine();
  14.             int[] emojiCodeArr = Console.ReadLine().Split(":").Select(int.Parse).ToArray();
  15.  
  16.             string emojiName = "";
  17.             for (int i = 0; i < emojiCodeArr.Length; i++)
  18.             {
  19.                 char curSymbol = (char)emojiCodeArr[i];
  20.                 emojiName += curSymbol;
  21.             }
  22.            
  23.             int totalPower = 0;
  24.             MatchCollection matchCollection = regex.Matches(givenMessage);
  25.  
  26.             foreach (var match in matchCollection)
  27.             {
  28.                 string calcMatch = match.ToString();
  29.                 for (int i = 1; i < calcMatch.Length - 1; i++)
  30.                 {
  31.                     totalPower += calcMatch[i];
  32.                 }
  33.             }
  34.  
  35.             foreach (var match in matchCollection)
  36.             {
  37.                 string tempMatch = match.ToString();
  38.                 string tempEmojiName = tempMatch.Remove(0, 1);
  39.                 tempEmojiName = tempEmojiName.Remove(tempEmojiName.Length - 1, 1);
  40.  
  41.                 if (tempEmojiName == emojiName)
  42.                 {
  43.                     totalPower *= 2;
  44.                     break;
  45.                 }
  46.             }
  47.  
  48.  
  49.             //if (string.Join("", matchCollection).Contains(emojiName))
  50.             //{
  51.             //    totalPower *= 2;
  52.             //}
  53.  
  54.             if (matchCollection.Count > 0)
  55.             {
  56.                 Console.WriteLine($"Emojis found: {string.Join(", ", matchCollection)}");
  57.             }
  58.            
  59.             Console.WriteLine($"Total Emoji Power: {totalPower}");
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement