Program.cs 577 B

12345678910111213141516171819
  1. using System;
  2. using System.IO;
  3. using System.Text.RegularExpressions;
  4. namespace D07._2
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. if (args.Length < 1) throw new ArgumentException();
  11. if (File.Exists(args[0]) == false) throw new FileNotFoundException();
  12. var r = new Regex(@"(\w)(?!\1)(\w)\1(?:(?!\w*\]).*\2\1\2(?=\w*\])|(?=\w*\]).*\2\1\2(?!\w*\]))", RegexOptions.Multiline)
  13. .Matches(File.ReadAllText(args[0]));
  14. Console.WriteLine($"The answer is : {r.Count}");
  15. }
  16. }
  17. }