Advertisement
TzvetanIG

Biggest Triple

Apr 15th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 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.         string input = Console.ReadLine();
  10.         string[] inputArray = input.Split(' ');
  11.         var listOfTriples = new List<int[]>();
  12.  
  13.         int TriplesNum = inputArray.Length / 3;
  14.         if (inputArray.Length % 3 > 0)
  15.         {
  16.             TriplesNum++;
  17.         }
  18.  
  19.         for (int i = 0; i < TriplesNum; i++)
  20.         {
  21.             int[] triple = new int[3];
  22.  
  23.             for (int j = 0; j < 3; j++)
  24.             {
  25.                 if (i * 3 + j < inputArray.Length)
  26.                 {
  27.                     triple[j] = int.Parse(inputArray[i * 3 + j]);
  28.                 }
  29.                 else
  30.                 {
  31.                     triple[j] = 0;
  32.                 }
  33.  
  34.             }
  35.             listOfTriples.Add(triple);
  36.         }
  37.  
  38.         int indexMax = 0;
  39.         int maxSum = int.MinValue;
  40.         int[] tripleMax = new int[3];
  41.  
  42.  
  43.         for (int i = 0; i < listOfTriples.Count; i++)
  44.         {
  45.             int sum = listOfTriples[i].Sum();
  46.             if (sum > maxSum)
  47.             {
  48.                 tripleMax = listOfTriples[i];
  49.                 maxSum = sum;
  50.                 indexMax = i;
  51.             }
  52.         }
  53.  
  54.         for (int i = 0; i < 3; i++)
  55.         {
  56.             if (indexMax * 3 + i < inputArray.Length)
  57.             {
  58.                 Console.Write(tripleMax[i] + " ");
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement