Advertisement
Guest User

01.Sum to 13

a guest
Jan 12th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Softuniada_2017
  8. {
  9.     class Program
  10.     {
  11.         static string output = "No";
  12.         static void Main(string[] args)
  13.         {
  14.             int[] numbers = Console.ReadLine()
  15.                            .Split()
  16.                            .Select(int.Parse)
  17.                            .ToArray();
  18.  
  19.             IsSumAchievable(numbers , 0);
  20.             Console.WriteLine(output);
  21.  
  22.         }
  23.  
  24.         static void IsSumAchievable(int[] numbers,int index)
  25.         {
  26.             if (index == 3)
  27.             {
  28.                 return;
  29.             }
  30.             for (int i = 0; i < 2 && output == "No"; i++)
  31.             {
  32.                 numbers[index] = i == 0 ? Math.Abs(numbers[index]) : 0 - Math.Abs(numbers[index]);
  33.                 int sum = numbers.Sum();
  34.                 if (sum == 13)
  35.                 {
  36.                     output = "Yes";
  37.                     return;
  38.                 }
  39.                 else
  40.                 {
  41.                     IsSumAchievable(numbers, index + 1);
  42.                 }
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement