Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class SpecialValue
- {
- static void SeparateNumbers(string[] allArrs)
- {
- string[][] numbArrInArr = new string[allArrs.Length][];
- intArrInArr = new int[allArrs.Length][];
- for (int i = 0; i < allArrs.Length; i++)
- {
- numbArrInArr[i] = allArrs[i].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- intArrInArr[i] = new int[numbArrInArr[i].Length];
- for (int j = 0; j < numbArrInArr[i].Length; j++)
- {
- intArrInArr[i][j] = int.Parse(numbArrInArr[i][j].Trim());
- }
- }
- }
- static int[][] intArrInArr;
- static int counter = 1;
- static int sum = 0;
- static int FindNumberOfCells(int currentArr, int currentIndex)
- {
- if ((currentArr >= intArrInArr.Length - 1) && counter == 1)
- {
- currentArr = 0;
- }
- int lastNumber = intArrInArr[currentArr][currentIndex];
- // проверяваме за изход
- counter++;
- sum = counter + Math.Abs(lastNumber);
- if (intArrInArr[currentArr][currentIndex] < 0)
- {
- //intArrInArr[currentArr][currentIndex] = int.MaxValue;
- return sum;
- }
- if (intArrInArr[currentArr][currentIndex] == int.MaxValue)
- {
- counter = 0;
- return sum;
- }
- if (intArrInArr[currentArr][currentIndex] >= 0)
- {
- int tempIndex = currentIndex;
- currentIndex = intArrInArr[currentArr][currentIndex];
- intArrInArr[currentArr][tempIndex] = int.MaxValue;
- if (currentArr >= intArrInArr.Length - 1)
- {
- currentArr = -1;
- }
- FindNumberOfCells(currentArr + 1, currentIndex);
- }
- return sum;
- }
- static void Main()
- {
- string input = Console.ReadLine(); //"2"; //
- int length = int.Parse(input);
- string[] allArrs = new string[length];
- for (int i = 0; i < allArrs.Length; i++)
- {
- allArrs[i] = Console.ReadLine();
- }
- //allArrs[0] = "3, 2, -8, -2, -5, -3, 0, -2";
- SeparateNumbers(allArrs);
- int sum = 0;
- int maxSum = 0;
- for (int j = 0; j < intArrInArr[0].Length; j++)
- {
- counter = 1;
- if (intArrInArr[0][j] < 0)
- {
- sum = counter + Math.Abs(intArrInArr[0][j]);
- }
- else if (intArrInArr[0][j] == int.MaxValue)
- {
- continue;
- }
- else if (intArrInArr[0][j] >= 0)
- {
- sum = FindNumberOfCells( 0 + 1, intArrInArr[0][j]);
- }
- if (maxSum < sum)
- {
- maxSum = sum;
- }
- }
- Console.WriteLine(maxSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement