-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathABSYS.cs
50 lines (43 loc) · 1.45 KB
/
ABSYS.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
using System;
// https://www.spoj.com/problems/ABSYS/ #ad-hoc #strings
// Takes an equation with an inkblot over one number, and removes the blot.
public static class ABSYS
{
// The inkblot is represented by the string "machula", apparently.
private const string _inkblot = "machula";
// For an equation of the form 'number + number = number', just identify
// over what number the blot exists and solve for it using algebra.
public static string Solve(string line)
{
string[] tokens = line.Split();
string firstNumber = tokens[0];
string secondNumber = tokens[2];
string thirdNumber = tokens[4];
if (firstNumber.Contains(_inkblot))
{
firstNumber = (int.Parse(thirdNumber) - int.Parse(secondNumber)).ToString();
}
else if (secondNumber.Contains(_inkblot))
{
secondNumber = (int.Parse(thirdNumber) - int.Parse(firstNumber)).ToString();
}
else
{
thirdNumber = (int.Parse(firstNumber) + int.Parse(secondNumber)).ToString();
}
return $"{firstNumber} + {secondNumber} = {thirdNumber}";
}
}
public static class Program
{
private static void Main()
{
int remainingTestCases = int.Parse(Console.ReadLine());
while (remainingTestCases-- > 0)
{
Console.ReadLine();
Console.WriteLine(
ABSYS.Solve(Console.ReadLine()));
}
}
}