Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class BiggestTriple
- {
- static void Main()
- {
- string input = Console.ReadLine();
- string[] inputArray = input.Split(' ');
- var listOfTriples = new List<int[]>();
- int TriplesNum = inputArray.Length / 3;
- if (inputArray.Length % 3 > 0)
- {
- TriplesNum++;
- }
- for (int i = 0; i < TriplesNum; i++)
- {
- int[] triple = new int[3];
- for (int j = 0; j < 3; j++)
- {
- if (i * 3 + j < inputArray.Length)
- {
- triple[j] = int.Parse(inputArray[i * 3 + j]);
- }
- else
- {
- triple[j] = 0;
- }
- }
- listOfTriples.Add(triple);
- }
- int indexMax = 0;
- int maxSum = int.MinValue;
- int[] tripleMax = new int[3];
- for (int i = 0; i < listOfTriples.Count; i++)
- {
- int sum = listOfTriples[i].Sum();
- if (sum > maxSum)
- {
- tripleMax = listOfTriples[i];
- maxSum = sum;
- indexMax = i;
- }
- }
- for (int i = 0; i < 3; i++)
- {
- if (indexMax * 3 + i < inputArray.Length)
- {
- Console.Write(tripleMax[i] + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement