Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace BiggestTriple
- {
- class BiggestTriple
- {
- static void Main(string[] args)
- {
- string inputNumbers = Console.ReadLine();
- string[] inputNumbersString = inputNumbers.Split();
- int maxTriple = int.MinValue;
- int numbersCounter = 0;
- int maxIndex = 0;
- int tripleSum = 0;
- bool flag = false;
- for (int i = 1; i <= (inputNumbersString.Length / 3); i++)
- {
- for (int j = 1; j <= 3; j++)
- {
- tripleSum += int.Parse(inputNumbersString[numbersCounter]);
- numbersCounter++;
- }
- if (tripleSum>maxTriple)
- {
- maxTriple = tripleSum;
- maxIndex = numbersCounter-1;
- }
- tripleSum = 0;
- }
- if (inputNumbersString.Length % 3 != 0)
- {
- for (int j = 1; j <= inputNumbersString.Length % 3; j++)
- {
- tripleSum += int.Parse(inputNumbersString[numbersCounter]);
- numbersCounter++;
- }
- if (tripleSum > maxTriple)
- {
- maxTriple = tripleSum;
- flag = true;
- maxIndex = numbersCounter-1;
- }
- tripleSum = 0;
- }
- if ((inputNumbersString.Length % 3 == 0) || !flag)
- {
- maxIndex = maxIndex - 2;
- for (int i = 0; i < 3; i++)
- {
- Console.Write(inputNumbersString[maxIndex]+" ");
- maxIndex++;
- }
- Console.WriteLine();
- }
- else if ((inputNumbersString.Length % 3 != 0) && flag)
- {
- maxIndex = maxIndex - (inputNumbersString.Length % 3-1);
- for (int i = 0; i < inputNumbersString.Length % 3; i++)
- {
- Console.Write(inputNumbersString[maxIndex]+" ");
- maxIndex++;
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement