Select() може да се прилага директно върху MatchCollection и така да се превърне в желаната колекция
2. Emoji Detector
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace exam
{
class Program
{
static void Main(string[] args)
{
string text = Console.ReadLine();
List<int> digits = Regex.Matches(text, @"\d").Select(x => int.Parse(x.Value)).ToList();
int sumCool = digits[0];
for (int i = 1; i < digits.Count; i++)
{
sumCool *= digits[ i ];
}
Console.WriteLine($"Cool threshold: {sumCool}");
MatchCollection emojis = Regex.Matches(text, @"([*:])\1([A-Z][a-z]{2,})\1{2}");
Console.WriteLine($"{emojis.Count} emojis found in the text. The cool ones are:");
foreach (Match match in emojis)
{
int sum = match.Groups[2].Value.Select(x => (int)(char.Parse(x.ToString()))).Sum();
if (sum >= sumCool)
{
Console.WriteLine(match.ToString());
}
}
}
}
}