Advertisement
Slamur

С# Solution template. Version 2.0

Dec 20th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Threading;
  7. using System.Globalization;
  8.  
  9. public class Solution
  10. {
  11.     // insert your code here
  12.     private void Solve()
  13.     {
  14.        
  15.     }
  16.  
  17.     bool ONLINE_JUDGE;
  18.  
  19.     public static void Main(string[] args)
  20.     {
  21.             new Solution().Run();
  22.     }
  23.        
  24.     public void Run()
  25.     {
  26.             try
  27.             {
  28.                     Init();
  29.                     Solve();
  30.  
  31.                     output.Close();
  32.             }
  33.             catch (Exception e)
  34.             {
  35.                 Console.Error.WriteLine(e.StackTrace);
  36.                 Console.Error.Flush();
  37.  
  38.                 throw e;
  39.             }
  40.     }
  41.  
  42.     private TextReader input;
  43.     private TextWriter output;
  44.  
  45.     private string[] INPUT_BUFFER;
  46.     private int INPUT_BUFFER_INDEX;
  47.  
  48.     private char[] DELIMITERS = new char[] { ' ', '\t' };
  49.  
  50.     private void Init()
  51.     {
  52.     #if (ONLINE_JUDGE)
  53.         ONLINE_JUDGE = true;
  54.     #else
  55.         ONLINE_JUDGE = false;
  56.     #endif
  57.  
  58.         try
  59.         {
  60.             Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  61.         }
  62.         catch (Exception ignored)
  63.         {
  64.         }
  65.  
  66.         if (ONLINE_JUDGE)
  67.         {
  68.             input = Console.In;
  69.             output = Console.Out;
  70.         }
  71.         else
  72.         {
  73.             string projectPath = Path.GetFullPath(@"..\..\");
  74.             input = new StreamReader(new FileStream(projectPath + "input.txt", FileMode.OpenOrCreate));
  75.             output = new StreamWriter(new FileStream(projectPath + "output.txt", FileMode.Create));
  76.         }
  77.  
  78.         INPUT_BUFFER = new string[0];
  79.         INPUT_BUFFER_INDEX = 0;
  80.     }
  81.        
  82.     private string ReadLine() { return input.ReadLine(); }
  83.        
  84.     private string ReadString()
  85.     {
  86.             while (INPUT_BUFFER_INDEX == INPUT_BUFFER.Length)
  87.             {
  88.                     INPUT_BUFFER = ReadLine().Split(DELIMITERS, StringSplitOptions.RemoveEmptyEntries);
  89.                     INPUT_BUFFER_INDEX = 0;
  90.             }
  91.                
  92.             return INPUT_BUFFER[INPUT_BUFFER_INDEX++];
  93.     }
  94.        
  95.     private int ReadInt() { return Int32.Parse(ReadString()); }
  96.        
  97.     private long ReadLong() { return Int64.Parse(ReadString()); }
  98.        
  99.     private double ReadDouble() { return Double.Parse(ReadString()); }
  100.  
  101.     private void WriteDouble(double value)
  102.     {
  103.         NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;
  104.         output.Write(string.Format(nfi, "{0}", value));
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement