Advertisement
Guest User

Biggest Triple

a guest
Apr 16th, 2015
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class BiggestTriple
  6. {
  7.     static void Main()
  8.     {
  9.         // read, split and parse input line, store in a list of unrestricted count
  10.         int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  11.  
  12.         // declaring variables
  13.         int maxSum = Int32.MinValue;
  14.         int sum = 0;
  15.  
  16.         List<int> temp = new List<int>();
  17.         List<int> final = new List<int>();
  18.  
  19.         for (int i = 0; i < numbers.Length; i +=3)
  20.         {
  21.             temp = numbers.Skip(i).Take(3).ToList();
  22.             sum = temp.Sum();
  23.  
  24.             if (sum > maxSum)
  25.             {
  26.                 maxSum = sum;
  27.                 final = temp;
  28.             }
  29.         }
  30.  
  31.         // printing the result
  32.         Console.WriteLine(string.Join(" ", final));
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement