-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-2.linq
34 lines (31 loc) · 803 Bytes
/
2-2.linq
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
<Query Kind="Program" />
void Main()
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(Util.CurrentQueryPath));
string[] inputLines = File.ReadAllLines("2.txt");
int sum = 0;
foreach (var inputLine in inputLines)
{
sum += FindSum(inputLine);
}
sum.Dump();
}
int FindSum(string inputLine)
{
int a = 0;
int b = 0;
var numbers = Regex.Matches(inputLine, @"[+-]?\d+(\.\d+)?");
for (int i = 0; i < numbers.Count - 1; i++)
{
a = int.Parse(numbers[i].Value);
for (int j = i + 1; j < numbers.Count; j++)
{
b = int.Parse(numbers[j].Value);
if (Math.Max(a, b) % Math.Min(a, b) == 0)
{
return Math.Max(a, b) / Math.Min(a, b);
}
}
}
return 0;
}