Program.cs 948 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. namespace D03._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. int answer = 0;
  13. var all = File.ReadAllText(args[0]).Split('\n', StringSplitOptions.RemoveEmptyEntries)
  14. .Select(a => a.Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(s => int.Parse(s)).ToArray());
  15. var lines = all.Select(a => a[0]).Concat(all.Select(a => a[1])).Concat(all.Select(a => a[2])).ToList();
  16. for (int i = 0; i < lines.Count; i += 3)
  17. answer += lines[i] + lines[i + 1] > lines[i + 2] && lines[i] + lines[i + 2] > lines[i + 1] && lines[i + 1] + lines[i + 2] > lines[i] ? 1 : 0;
  18. Console.WriteLine($"The answer is : {answer}");
  19. }
  20. }
  21. }