-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGCJ2018_Problem.cs
107 lines (95 loc) · 2.93 KB
/
GCJ2018_Problem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
namespace Contest
{
public class GCJ2018_Problem
{
protected void SolveAndWrite(int problemIndex, TextWriter writer)
{
}
protected void ReadInput(TextReader reader)
{
}
public void Run()
{
TextReader reader = null;
TextWriter writer = null;
try
{
reader = new StreamReader("input.txt");
writer = new StreamWriter("output.txt");
// The default buffer size for the console is 256 bytes.
// Depending on the size of the input this might not be enough.
reader = Console.In;
writer = Console.Out;
int problemCount = Helper.ParseInt(reader.ReadLine());
for (int problemIndex = 1; problemIndex <= problemCount; problemIndex++)
{
ReadInput(reader);
writer.Write("Case #{0}: ", problemIndex);
SolveAndWrite(problemIndex, writer);
writer.WriteLine();
}
}
catch (Exception e)
{
String msg = "Exception: " + e;
Console.WriteLine(msg);
Debug.Fail(msg);
}
finally
{
if (reader != null)
reader.Dispose();
if (writer != null)
writer.Dispose();
}
}
}
/// <summary>
/// Helpers for converting input/output data.
/// </summary>
public class Helper
{
/// <summary>
/// Run one problem at a time.
/// Just initialize the solver with the correct one.
/// </summary>
public static void Main(string[] args)
{
GCJ2018_Problem instance = new GCJ2018_Problem();
instance.Run();
}
public static int ParseInt(string value)
{
return Int32.Parse(value, FormatProvider);
}
public static double ParseDouble(string value)
{
return Double.Parse(value, FormatProvider);
}
public static float ParseFloat(string value)
{
return Single.Parse(value, FormatProvider);
}
public static int[] ParseInts(string line)
{
string[] parts = line.Split(' ');
int[] result = new int[parts.Length];
for (int i = 0; i < parts.Length; i++)
{
result[i] = ParseInt(parts[i]);
}
return result;
}
public static string ToStr(double v)
{
return v.ToString(FormatProvider);
}
public static readonly IFormatProvider FormatProvider = CultureInfo.InvariantCulture;
}
}