Advertisement
Guest User

Problem 2. Destination Mapper

a guest
Aug 14th, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  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.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement