Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Numerics;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace _02.Emoji_Detector
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- //emoji matches:
- string regex = @"(::|\*\*)(?<emojis>[A-Z][a-z]{2,})(\1)";
- MatchCollection matches = Regex.Matches(input, regex);
- //numbers matches:
- Regex numRegex = new Regex(@"\d");
- MatchCollection numMatches = numRegex.Matches(input);
- int coolTreshold = 1;
- foreach (Match numMatch in numMatches)
- {
- coolTreshold *= int.Parse(numMatch.Value);
- }
- Console.WriteLine($"Cool threshold: {coolTreshold}");
- int emojiCharSum = 0;
- int emojiCount = 0;
- foreach (Match match in matches)
- {
- emojiCount++;
- }
- Console.WriteLine($"{emojiCount} emojis found in the text. The cool ones are:");
- foreach (Match match in matches)
- {
- var charValues = Encoding.ASCII.GetBytes(match.Groups["emojis"].Value);
- foreach (var charVal in charValues)
- {
- emojiCharSum += charVal;
- }
- if (coolTreshold < emojiCharSum)
- {
- Console.WriteLine(match.Value);
- }
- emojiCharSum = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement