Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace WordEncounter
  9. {
  10. class WordEncounter
  11. {
  12. static void Main(string[] args)
  13. {
  14. var filter = Console.ReadLine();
  15. var line = Console.ReadLine();
  16. var result = new List<string>();
  17.  
  18. while (line != "end")
  19. {
  20. //Check's for sentance match.
  21. var isMatch = Regex.IsMatch(line, @"(?<!.)[A-Z](.*)[.!?](?!.)"); //negative lookbehind and negative lookahead.
  22.  
  23. if (isMatch)
  24. {
  25. //Take's each word from sentance.
  26. var words = Regex.Matches(line, @"(\w+)");
  27.  
  28. foreach (Match word in words)
  29. {
  30. var letter = filter[0];
  31. var minLenght = int.Parse(filter[1].ToString());
  32. var currentWord = word.Groups[0].Value;
  33. var counter = 0;
  34. for (int i = 0; i < currentWord.Length; i++)
  35. {
  36. if (currentWord[i] == letter)
  37. {
  38. counter++;
  39. }
  40. }
  41.  
  42. if (counter >= minLenght)
  43. {
  44. result.Add(currentWord);
  45. }
  46.  
  47. counter = 0;
  48. }
  49. }
  50.  
  51. line = Console.ReadLine();
  52. }
  53.  
  54. Console.WriteLine(string.Join(", ", result));
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement