Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Solution1()
- {
- int target;
- string[] numStrings;
- Dictionary<int, int> dict = new Dictionary<int, int>();
- using (var sr = File.OpenText("input.txt"))
- {
- target = int.Parse(sr.ReadLine());
- numStrings = sr.ReadLine().Split(new char[] { ' ' });
- }
- foreach (var numStr in numStrings)
- {
- int num = int.Parse(numStr);
- if (num >= target)
- {
- continue;
- }
- if (dict.ContainsKey(num))
- {
- dict[num] += 1;
- }
- else
- {
- dict.Add(num, 1);
- }
- }
- foreach (var pair in dict)
- {
- if (dict.ContainsKey(target - pair.Key)
- && (pair.Key != target - pair.Key)
- || (pair.Key == target - pair.Key
- && pair.Value > 1))
- {
- using (var sw = File.CreateText("output.txt"))
- {
- sw.WriteLine(1);
- return;
- }
- }
- }
- using (var sw = File.CreateText("output.txt"))
- {
- sw.WriteLine(0);
- }
- System.Console.ReadKey();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement