Program.cs 737 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.IO;
  3. namespace D01._2
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. if (args.Length < 1) return;
  10. if (File.Exists(args[0]) == false) throw new FileNotFoundException();
  11. int floor = 0;
  12. string text = "";
  13. using (var file = File.OpenText(args[0]))
  14. {
  15. text = file.ReadToEnd();
  16. }
  17. int c = 0;
  18. foreach (var car in text)
  19. {
  20. c++;
  21. if (car == '(') floor++;
  22. if (car == ')') floor--;
  23. if (floor == -1) break;
  24. }
  25. Console.WriteLine($"Answer is : {c}");
  26. }
  27. }
  28. }