Program.cs 903 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.IO;
  3. using System.Text.RegularExpressions;
  4. namespace D08._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 original = 0, escaped = 0;
  13. using (var file = File.OpenText(args[0]))
  14. {
  15. while (true)
  16. {
  17. var line = file.ReadLine();
  18. if (line == null) break;
  19. var nstring = '"' + Regex.Escape(line).Replace("\"", "\\\"") + '"';
  20. original += line.Length;
  21. escaped += nstring.Length;
  22. }
  23. }
  24. int answer = escaped - original;
  25. Console.WriteLine($"The answer is : {answer}");
  26. }
  27. }
  28. }