Advertisement
GogoK

BiggestTriple

Dec 14th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class BiggestTriple
  5. {
  6.     static void Main()
  7.     {
  8.         int[] myArr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  9.        
  10.         int bestSum = 0;
  11.        
  12.         int index = 0;
  13.         int steps = 0;
  14.        
  15.         for (int i = 0; i < myArr.Length; i += 3)
  16.         {
  17.             int tempSum = 0;
  18.             int nextIndexes = i + 3;
  19.             int stepCounter = 0;
  20.  
  21.             for (int t = i; t < (3 + i) && (t < myArr.Length); t++)
  22.             {
  23.                 tempSum += myArr[t];
  24.                 stepCounter++;
  25.             }
  26.  
  27.             if (tempSum > bestSum)
  28.             {
  29.                 index = i;
  30.                 steps = stepCounter;
  31.                 bestSum = tempSum;
  32.             }
  33.         }
  34.  
  35.         int[] output = new int[steps];
  36.         for (int i = 0; i < steps; i++)
  37.         {
  38.             output[i] = myArr[index + i];
  39.         }
  40.         Console.WriteLine(string.Join(" ", output));
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement