Advertisement
Guest User

Emoji Sumator

a guest
Dec 15th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Emoji_Sumator
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string line = Console.ReadLine();
  11.             //string[] lineSplit = line.Split(" :");
  12.             string emojiCode = Console.ReadLine();
  13.             string[] emojiCodeSplit = emojiCode.Split(":");
  14.             List<string> emojiFound = new List<string>();
  15.                        
  16.             for (int i = 1; i < line.Length; i++)
  17.             {
  18.                 string emoji = string.Empty;
  19.  
  20.                 if (line[i] == ':' && line[i-1] == ' ')
  21.                 {
  22.                     for (int j = i + 1; j < line.Length; j++)
  23.                     {
  24.                         if (line[j] >= 97 && line[j] <= 122)
  25.                         {
  26.                             emoji += line[j];
  27.                         }
  28.                         else if (line[j] == ':' && j+1 < line.Length &&
  29.                             (line[j + 1] == ' ' ||  line[j+1] == ',' || line[j + 1] == '.' || line[j + 1] == '!' || line[j + 1] == '?'))
  30.                         {
  31.                             if (emoji.Length >= 4)
  32.                             {
  33.                                 emoji = ":" + emoji + ":";
  34.                                 emojiFound.Add(emoji);
  35.                             }
  36.                         }
  37.                         else
  38.                         {
  39.                             break;
  40.                         }
  41.  
  42.                         i = j;
  43.                     }
  44.                 }
  45.             }
  46.  
  47.             int totalPower = 0;
  48.             string emojiInputName = string.Empty;
  49.  
  50.             foreach (var ch in emojiCodeSplit)
  51.             {
  52.                 emojiInputName += (char)int.Parse(ch);
  53.             }
  54.  
  55.             emojiInputName = ":" + emojiInputName + ":";
  56.  
  57.             foreach (var emoji in emojiFound)
  58.             {
  59.                 int currentEmojiPower = 0;
  60.  
  61.                 for (int i = 1; i < emoji.Length -1; i++)
  62.                 {
  63.                     currentEmojiPower += (int)emoji[i];
  64.                 }
  65.  
  66.                 totalPower += currentEmojiPower;
  67.             }
  68.  
  69.  
  70.             if (emojiFound.Contains(emojiInputName))
  71.             {
  72.                 totalPower *= 2;
  73.             }
  74.  
  75.             if (emojiFound.Count > 0)
  76.             {
  77.                 Console.WriteLine("Emojis found: " + String.Join(", ", emojiFound));
  78.             }
  79.            
  80.             Console.WriteLine($"Total Emoji Power: {totalPower}");
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement