Yachkov

easter eggs

Dec 5th, 2021
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace EasterEggs {
  5.     class Program {
  6.         static void Main(string[] args) {
  7.             string input = Console.ReadLine();
  8.             Regex rule = new Regex(@"(@|#)([a-z]{3,})(@|#)[^a-z0-9]*/\d{1,}/");
  9.  
  10.             foreach (Match match in rule.Matches(input)) {
  11.                 string colorMatch = Regex.Match(match.ToString(), @"(@|#)([a-z]{3,})(@|#)").ToString();
  12.                 string color = colorMatch.Substring(1, colorMatch.Length - 2);
  13.                 string amountMatch = Regex.Match(match.ToString(), @"/\d{1,}/").ToString();
  14.                 int amount = Convert.ToInt32(amountMatch.Substring(1, amountMatch.Length - 2));
  15.                 Console.WriteLine($"You found {amount} {color} eggs!");
  16.             }
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment