| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System;
- using System.IO;
- namespace D05._1
- {
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length < 1) throw new ArgumentException();
- if (File.Exists(args[0]) == false) throw new FileNotFoundException();
- int goodStrings = 0;
- using (var file = File.OpenText(args[0]))
- {
- while (true)
- {
- var line = file.ReadLine();
- if (line == null) break;
- if (IsGoodString(line)) goodStrings++;
- }
- }
- Console.WriteLine($"The answer is : {goodStrings}");
- }
- private static bool IsGoodString(string line)
- {
- int vowels = 0;
- int repeted = 0;
- bool isBad = false;
- char last = '\0';
- foreach (var c in line)
- {
- if (c == 'a' || c == 'o' || c == 'i' || c == 'e' || c == 'u') vowels++;
- if (c == last) repeted++;
- if ((last == 'a' && c == 'b') || (last == 'c' && c == 'd') || (last == 'p' && c == 'q') || (last == 'x' && c == 'y'))
- {
- isBad = true;
- break;
- }
- last = c;
- }
- return isBad == false && repeted > 0 && vowels >= 3;
- }
- }
- }
|