Advertisement
silvana1303

destination mapper

Oct 9th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Text;
  6.  
  7.  
  8. namespace Final_Exam
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string input = Console.ReadLine();
  15.  
  16.             Regex regex = new Regex(@"(\=|\/)(?<name>[A-Z][a-zA-Z]{2,})(\1)");
  17.  
  18.             MatchCollection match = regex.Matches(input);
  19.  
  20.             List<string> destination = new List<string>();
  21.  
  22.             int points = 0;
  23.  
  24.             foreach (Match item in match)
  25.             {
  26.                 if (item.Success)
  27.                 {
  28.                     string name = item.Groups["name"].Value;
  29.                     destination.Add(name);
  30.                     points += name.Length;
  31.                 }
  32.             }
  33.  
  34.             Console.WriteLine($"Destinations: {string.Join(", ",destination)}");
  35.  
  36.             Console.WriteLine($"Travel Points: {points}");
  37.  
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement