svephoto

Destination Mapper [C#]

Mar 31st, 2021 (edited)
928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;  
  4.                    
  5. public class Program
  6. {
  7.     public static void Main(string[] args)
  8.     {
  9.         string text = Console.ReadLine();
  10.  
  11.         string pattern = @"([=/])([A-Z][A-Za-z]{2,})\1";       
  12.         Regex regex = new Regex(pattern, RegexOptions.Compiled);
  13.  
  14.         int travelPoints = 0;
  15.  
  16.         List<string> listOfDestinations = new List<string>();
  17.  
  18.         foreach (Match currentMatch in regex.Matches(text))
  19.         {
  20.             travelPoints += currentMatch.Groups[2].Length;
  21.             string currentDestination = currentMatch.Groups[2].Value;
  22.             listOfDestinations.Add(currentDestination);
  23.         }
  24.  
  25.         string destinations = String.Join(", ", listOfDestinations);
  26.            
  27.         Console.WriteLine("Destinations: " + destinations);
  28.         Console.WriteLine("Travel Points: " + travelPoints);       
  29.     }
  30. }
  31.  
Add Comment
Please, Sign In to add comment