1  using System;
   2  using System.IO;
   3  
   4  class Program {
   5      static void Main(string[] args) {
   6          // for(int k = 0; k<10000; ++k)  // 82 S runtime in release mode (for performance test)
   7          try {
   8              // If optional second argument exists, write graphical maze (for extra credit).
   9              bool extraCredit = args.Length>1;
  10  
  11              // Read N
  12              StreamReader reader = new StreamReader(args[0]);
  13              int N = Convert.ToInt32(reader.ReadLine());
  14  
  15              // Open output file:
  16              string filename = System.IO.Path.GetFileNameWithoutExtension(args[0]);
  17              TextWriter tw = new StreamWriter(filename + (extraCredit?"GR":"") + ".txt");
  18  
  19              // For each case, read input file, process, and write output file:
  20              for(int i = 1; i<=N; ++i) {
  21  
  22                  // Read and parse problem:
  23                  string problem = reader.ReadLine();
  24                  string[] parts = problem.Split(' ');
  25                  string forward = parts[0];
  26                  string backward = parts[1];
  27  
  28                  tw.WriteLine("Case #" + i + ':');
  29                  TestCase testCase = new TestCase(forward, backward);
  30                  testCase.execute();
  31                  
  32                  // Write maze to file:
  33                  if (extraCredit) testCase.maze_.writeGraphically(tw);
  34                  else             testCase.maze_.write(tw);
  35                  }
  36  
  37              tw.Close();
  38              reader.Close();
  39              }
  40  
  41          catch(Exception x) {Console.Write(x.Message.ToString());}
  42          }
  43  }