Program.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.IO;
  3. namespace D05._1
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. if (args.Length < 1) throw new ArgumentException();
  10. if (File.Exists(args[0]) == false) throw new FileNotFoundException();
  11. int goodStrings = 0;
  12. using (var file = File.OpenText(args[0]))
  13. {
  14. while (true)
  15. {
  16. var line = file.ReadLine();
  17. if (line == null) break;
  18. if (IsGoodString(line)) goodStrings++;
  19. }
  20. }
  21. Console.WriteLine($"The answer is : {goodStrings}");
  22. }
  23. private static bool IsGoodString(string line)
  24. {
  25. int vowels = 0;
  26. int repeted = 0;
  27. bool isBad = false;
  28. char last = '\0';
  29. foreach (var c in line)
  30. {
  31. if (c == 'a' || c == 'o' || c == 'i' || c == 'e' || c == 'u') vowels++;
  32. if (c == last) repeted++;
  33. if ((last == 'a' && c == 'b') || (last == 'c' && c == 'd') || (last == 'p' && c == 'q') || (last == 'x' && c == 'y'))
  34. {
  35. isBad = true;
  36. break;
  37. }
  38. last = c;
  39. }
  40. return isBad == false && repeted > 0 && vowels >= 3;
  41. }
  42. }
  43. }