kirililchev3

Triple SUm

Jun 3rd, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. namespace Tripple_Sum
  2. {
  3.     using System;
  4.     using System.Linq;
  5.  
  6.     public class Tripple_Sum
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             string input = Console.ReadLine();
  11.             int lengthOfTheArray = 0;
  12.             for (int i = 0; i < input.Length; i++)
  13.             {
  14.                 if (input[i].Equals(' '))
  15.                 {
  16.                     lengthOfTheArray++;
  17.                 }
  18.             }
  19.  
  20.             lengthOfTheArray++;
  21.             int[] numbers = new int[lengthOfTheArray];
  22.  
  23.             for (int i = 0; i < numbers.Length; i++)
  24.             {
  25.                 if (input.Contains(" "))
  26.                 {
  27.                     numbers[i] = int.Parse(input.Substring(0, input.IndexOf(' ')));
  28.                     input = input.Substring(input.IndexOf(' ') + 1);
  29.                 }
  30.                 else
  31.                 {
  32.                     numbers[i] = int.Parse(input);
  33.                 }
  34.             }
  35.  
  36.             string output = string.Empty;
  37.             for (int i = 0; i < numbers.Length; i++)
  38.             {
  39.                 for (int j = i + 1; j < numbers.Length; j++)
  40.                 {
  41.                     if (numbers.Contains(numbers[i] + numbers[j]))
  42.                     {
  43.                         output += $"{numbers[i]} + {numbers[j]} == {numbers[i] + numbers[j]}\n";
  44.                     }
  45.                 }
  46.             }
  47.  
  48.             Console.Write(output.Length > 0 ? output : "No");
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment