Program.cs 663 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.IO;
  3. using System.Text.RegularExpressions;
  4. namespace D12._1
  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 input = File.ReadAllText(args[0]);
  13. int answer = 0;
  14. var regex = new Regex(@"(-?\d+)");
  15. var matches = regex.Matches(input);
  16. foreach (Match match in matches)
  17. answer += int.Parse(match.Value);
  18. Console.WriteLine($"The answer is : {answer}");
  19. }
  20. }
  21. }