Advertisement
elena1234

DestinationMapper-ExamPreparation

Dec 3rd, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Collections.Generic;
  4.  
  5. namespace DestinationMapper
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string map = Console.ReadLine();
  12.             Regex regexforPlaces = new Regex(@"(=|\/)(?<place>[A-Z][A-Za-z]{2,})(\1)");
  13.             MatchCollection matchesPlaces = regexforPlaces.Matches(map);
  14.             var listWithPlaces = new List<string>();
  15.             int travelPoints = 0;
  16.             foreach (Match match in matchesPlaces)
  17.             {
  18.                 string place = match.Groups["place"].Value;
  19.                 listWithPlaces.Add(place);
  20.                 int length = place.Length;
  21.                 travelPoints += length;
  22.             }
  23.  
  24.             Console.WriteLine($"Destinations: {string.Join(", ",listWithPlaces)}");
  25.             Console.WriteLine($"Travel Points: {travelPoints}");
  26.  
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement