-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
76 lines (68 loc) · 2.98 KB
/
Program.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
namespace LazyMathInstructor
{
public class Program
{
/// <summary>
/// Indicates if the program was started with the --verbose flag
/// and should output (intermediate) parsing results.
/// </summary>
public static bool Verbose { get; private set; }
/// <summary>
/// Reads the input from STDIN, parses the terms and returns them in a list of tuples
/// of two polynomials each, that are to be checked for equivalence.
/// </summary>
static List<(Polynomial First, Polynomial Second)> ParseInputTerms()
{
var polynomials = new List<(Polynomial First, Polynomial Second)>();
int n = int.Parse(Console.ReadLine()!);
for (int i = 0; i < n; i++)
{
Polynomial first = Polynomial.Parse(Console.ReadLine()!.Replace(" ", "").Replace("\t", ""));
if (Program.Verbose) Console.WriteLine();
Polynomial second = Polynomial.Parse(Console.ReadLine()!.Replace(" ", "").Replace("\t", ""));
if (Program.Verbose) Console.WriteLine();
polynomials.Add((first, second));
}
return polynomials;
}
/// <summary>
/// Print help message when the program is called with -h or --help command line argument.
/// </summary>
static void PrintHelpMessage()
{
Console.WriteLine("LazyMathInstructor by Ludwig Kolesch\n" +
"Source and explanation: https://github.com/Ludwig-Uni/Lazy-Math-Instructor\n" +
"Usage: Enter the number of equivalences to test and all the terms via STDIN.\n" +
"Terminate each input with a newline.\n" +
"\n" +
"Options:\n" +
" -v, --verbose: Output parsed polynomials step-by-step\n" +
" -h, --help: Display this message");
}
/// <summary>
/// Entry point of the program. Reads input from STDIN and prints YES or NO for each pair of terms
/// entered, depending on whether they are equivalent, according to the specification.
/// </summary>
static void Main(string[] args)
{
if (args.Contains("-h") || args.Contains("--help"))
{
PrintHelpMessage();
return;
}
Console.WriteLine("LazyMathInstructor by Ludwig Kolesch\nReading input from STDIN now.\n");
Verbose = args.Contains("-v") || args.Contains("--verbose");
var polynomials = ParseInputTerms();
Console.WriteLine();
foreach (var (first, second) in polynomials)
{
Console.WriteLine(first.Equals(second) ? "YES" : "NO");
if (Verbose)
{
Console.WriteLine("First: " + first.ToString());
Console.WriteLine("Second: " + second.ToString());
}
}
}
}
}