Advertisement
kiraventom

Untitled

May 30th, 2020
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. static void Solution1()
  2.         {
  3.             int target;
  4.             string[] numStrings;
  5.             Dictionary<int, int> dict = new Dictionary<int, int>();
  6.             using (var sr = File.OpenText("input.txt"))
  7.             {
  8.                 target = int.Parse(sr.ReadLine());
  9.                 numStrings = sr.ReadLine().Split(new char[] { ' ' });
  10.             }
  11.  
  12.             foreach (var numStr in numStrings)
  13.             {
  14.                 int num = int.Parse(numStr);
  15.                 if (num >= target)
  16.                 {
  17.                     continue;
  18.                 }
  19.  
  20.                 if (dict.ContainsKey(num))
  21.                 {
  22.                     dict[num] += 1;
  23.                 }
  24.                 else
  25.                 {
  26.                     dict.Add(num, 1);
  27.                 }
  28.             }
  29.  
  30.             foreach (var pair in dict)
  31.             {
  32.                 if (dict.ContainsKey(target - pair.Key)
  33.                     && (pair.Key != target - pair.Key)
  34.                     || (pair.Key == target - pair.Key
  35.                         && pair.Value > 1))
  36.                 {
  37.                     using (var sw = File.CreateText("output.txt"))
  38.                     {
  39.                         sw.WriteLine(1);
  40.                         return;
  41.                     }
  42.                 }
  43.             }
  44.             using (var sw = File.CreateText("output.txt"))
  45.             {
  46.                 sw.WriteLine(0);
  47.             }
  48.             System.Console.ReadKey();
  49.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement