Guest User

Problem 2. Destination Mapper

a guest
Aug 14th, 2020
13
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Example
  7. {
  8. public static void Main()
  9. {
  10. List<string> validWords = new List<string>();
  11. string input = Console.ReadLine();
  12. string pattern = @"([=,]|[\/,])(?<Match>[[A-Z]{1}[a-z]{3,})(\1)";
  13.  
  14. MatchCollection matches = Regex.Matches(input, pattern);
  15. int matchedWordsCount = 0;
  16. int totalLenghtOfMatches = 0;
  17. foreach (Match match in matches)
  18. {
  19. var word = match.Groups["Match"].Value;
  20. totalLenghtOfMatches += word.Length;
  21. validWords.Add(word);
  22. matchedWordsCount++;
  23. }
  24. if (matchedWordsCount >= 1)
  25. {
  26. Console.WriteLine("Destinations: " + string.Join(", ", validWords));
  27. Console.WriteLine("Travel Points: " + totalLenghtOfMatches);
  28. }
  29. else
  30. {
  31. Console.WriteLine("Destinations: " + string.Join(", ", validWords));
  32. Console.WriteLine("Travel Points: " + totalLenghtOfMatches);
  33. }
  34. }
  35. }
  36.  
RAW Paste Data