Advertisement
a_tifonoff

Biggest Triple

Mar 20th, 2015
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace BiggestTriple
  8. {
  9.     class BiggestTriple
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string inputNumbers = Console.ReadLine();
  14.             string[] inputNumbersString = inputNumbers.Split();
  15.             int maxTriple = int.MinValue;
  16.             int numbersCounter = 0;
  17.             int maxIndex = 0;
  18.             int tripleSum = 0;
  19.             bool flag = false;
  20.                 for (int i = 1; i <= (inputNumbersString.Length / 3); i++)
  21.                 {
  22.                     for (int j = 1; j <= 3; j++)
  23.                     {
  24.                         tripleSum += int.Parse(inputNumbersString[numbersCounter]);
  25.                         numbersCounter++;
  26.                     }
  27.                     if (tripleSum>maxTriple)
  28.                     {
  29.                         maxTriple = tripleSum;
  30.                         maxIndex = numbersCounter-1;
  31.                     }
  32.                     tripleSum = 0;
  33.                 }
  34.             if (inputNumbersString.Length % 3 != 0)
  35.             {
  36.                    
  37.                     for (int j = 1; j <= inputNumbersString.Length % 3; j++)
  38.                     {
  39.                         tripleSum += int.Parse(inputNumbersString[numbersCounter]);
  40.                         numbersCounter++;
  41.                     }
  42.                     if (tripleSum > maxTriple)
  43.                     {
  44.                         maxTriple = tripleSum;
  45.                         flag = true;
  46.                         maxIndex = numbersCounter-1;
  47.                     }
  48.                     tripleSum = 0;
  49.                
  50.             }
  51.             if ((inputNumbersString.Length % 3 == 0) || !flag)
  52.             {
  53.                 maxIndex = maxIndex - 2;
  54.                 for (int i = 0; i < 3; i++)
  55.                 {
  56.                    
  57.                     Console.Write(inputNumbersString[maxIndex]+" ");
  58.                     maxIndex++;
  59.                 }
  60.                 Console.WriteLine();
  61.             }
  62.             else if ((inputNumbersString.Length % 3 != 0) && flag)
  63.             {
  64.                 maxIndex = maxIndex - (inputNumbersString.Length % 3-1);
  65.                 for (int i = 0; i < inputNumbersString.Length % 3; i++)
  66.                 {
  67.                     Console.Write(inputNumbersString[maxIndex]+" ");
  68.                     maxIndex++;
  69.                 }
  70.                 Console.WriteLine();
  71.             }
  72.  
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement