Advertisement
stanevplamen

03.02.07.AkademyTasks

Jul 26th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         int arrayLength = int.Parse(Console.ReadLine());//5;
  8.         string inputLine = Console.ReadLine(); //  "1 2 3 4 5";
  9.  
  10.         string[] numbsStr = inputLine.Split();
  11.  
  12.         int indicatorNumb = int.Parse(Console.ReadLine()); //3;
  13.  
  14.         int[] numbersToCompare = new int[numbsStr.Length];
  15.  
  16.         for (int i = 0; i < numbsStr.Length; i++)
  17.         {
  18.             numbersToCompare[i] = int.Parse(numbsStr[i]);
  19.         }
  20.        
  21.         int[,] resultMatrix = new int[arrayLength, arrayLength];
  22.  
  23.         for (int col = 0; col < resultMatrix.GetLength(1); col++)
  24.         {
  25.             for (int row = col+1; row < resultMatrix.GetLength(0); row++)
  26.             {
  27.                 resultMatrix[row, col] = Math.Abs(numbersToCompare[col] - numbersToCompare[row]);
  28.             }
  29.         }
  30.  
  31.         int minRow = 0;
  32.         int minCol = 0;
  33.         bool isBreak = false;
  34.         for (int row = 1; row < resultMatrix.GetLength(0); row++)
  35.         {
  36.             for (int col = 0; col <= row; col++)
  37.             {
  38.                 if (resultMatrix[row, col] >= indicatorNumb)
  39.                 {
  40.                     minRow = row;
  41.                     minCol = col;
  42.                     isBreak = true;
  43.                     break;
  44.                 }
  45.             }
  46.             if (isBreak == true)
  47.             {
  48.                 break;
  49.             }
  50.         }
  51.         int sum = 1;
  52.         if (true)
  53.         {
  54.             int divideOne = minCol / 2;
  55.             int remainOne = minCol % 2;
  56.             if (remainOne == 0)
  57.             {
  58.                 sum = sum + divideOne;
  59.             }
  60.             else
  61.             {
  62.                 sum = sum + divideOne + 1;
  63.             }
  64.  
  65.             int substractOne = minRow - minCol;
  66.             int divideTwo = substractOne / 2;
  67.             int remainTwo = substractOne % 2;
  68.  
  69.             if (remainTwo == 0)
  70.             {
  71.                 sum = sum + divideTwo;
  72.             }
  73.             else
  74.             {
  75.                 sum = sum + divideTwo + 1;
  76.             }
  77.         }
  78.         if (sum == 1)
  79.         {
  80.             Console.WriteLine(arrayLength);
  81.         }
  82.         else
  83.         {
  84.             Console.WriteLine(sum);
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement