-
-
Notifications
You must be signed in to change notification settings - Fork 414
/
Copy pathsolution.cs
35 lines (32 loc) · 1.02 KB
/
solution.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
using System;
using System.Collections.Generic;
using System.Linq;
namespace Solution {
class Program {
static void Main(string[] args) {
var input = args[0].Split(',').Select(int.Parse).ToArray();
var k = input[0];
var seen = new HashSet<int>();
var pairs = new List<(int x, int y)>();
for (var i = 1; i < input.Length; i++) {
var n = input[i];
var x = k - n;
if (x != n) {
if (seen.Contains(x)) {
pairs.Add((Math.Min(x, n), Math.Max(x, n)));
} else {
seen.Add(n);
}
}
}
Console.Write('[');
for (var i = 0; i < pairs.Count; i++) {
if (i != 0) {
Console.Write(", ");
}
Console.Write("(" + pairs[i].x + ", " + pairs[i].y + ")");
}
Console.Write(']');
}
}
}