Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. namespace _01.ExtractPersonInformation
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Text.RegularExpressions;
  6.  
  7.     public class Program
  8.     {
  9.         public static void Main()
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.  
  13.            
  14.             Regex namePattern = new Regex(@"@(?<name>[\S\s]*?)\|");
  15.             Regex agePattern = new Regex(@"#(?<age>[\S\s]*?)\*");
  16.  
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 string input = Console.ReadLine();
  20.  
  21.                 if (namePattern.IsMatch(input) && agePattern.IsMatch(input))
  22.                 {
  23.                   Console.WriteLine($"{namePattern.Match(input).Groups["name"].ToString()} is {agePattern.Match(input).Groups["age"].ToString()} years old.");
  24.                 }
  25.             }
  26.  
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement