public void TestCase1() { //Arrange string fileName = "input01.txt"; string path = Path.Combine(Environment.CurrentDirectory, @"Array\Data\TwoDArrayTest\input\", fileName); String input = File.ReadAllText(path); int i = 0, j = 0; int[][] arr = new int[6][]; foreach (var row in input.Split('\n')) { j = 0; arr[i] = new int[6]; foreach (var col in row.Trim().Split(' ')) { arr[i][j] = int.Parse(col.Trim()); j++; } i++; } //Act int result = TwoDArray.HourglassSum(arr); ////Assert Assert.AreEqual(13, result); }
static void Task5() { Console.WriteLine("Задача 5. Класс библиотченый TwoDArray."); TwoDArray twoDArr = new TwoDArray(10, -5000, 5000); // сначала использовать эту строку //TwoDArray twoDArr = new TwoDArray("twoDArray.txt"); // после создания файла можно использовать эту строку Console.WriteLine("Элементы массива: \n{0}", twoDArr.ToString()); Console.WriteLine("Sum: " + twoDArr.Sum()); Console.WriteLine("Sum Greater Then 1000: " + twoDArr.SumGreaterThen(1000)); Console.WriteLine("Min: " + twoDArr.Min); Console.WriteLine("Max: " + twoDArr.Max); int row, column; twoDArr.MaxElementPosition(out row, out column); Console.WriteLine($"Max Element position: [{row}, {column}]"); twoDArr.WriteInFile("twoDArray.txt"); }
public void init() { map = new TwoDArray((int)size.x + 2, (int)size.y + 2); destroy(); for (int x = 1; x < size.x + 1; x++) { for (int y = 1; y < size.y + 1; y++) { map [x] [y] = 0; Transform t = (Instantiate(segmentPrefab) as Transform); t.GetComponent <LevelSegment>().x = x; t.GetComponent <LevelSegment>().y = y; t.GetComponent <LevelSegment>().level = this; t.transform.localPosition = new Vector3(x, 0, y); t.parent = segments; } } segments.localScale = new Vector3(1, 1, -1); segments.localPosition = new Vector3(-(size.x + 1) / 2, 0, (size.y + 1) / 2); }
public int FindLongestChain(int[,] pairs) { int n = pairs.GetLength(0); int[] dp = new int[pairs.Length]; for (int i = 0; i < n; i++) { dp[i] = 1; } #region Sorting the pairs array!!! TwoDArray[] temparray = new TwoDArray[n]; for (int i = 0; i < n; i++) { temparray[i] = new TwoDArray(new int[] { pairs[i, 0], pairs[i, 1] }); } Array.Sort(temparray); for (int i = 0; i < n; i++) { pairs[i, 0] = temparray[i].array[0]; pairs[i, 1] = temparray[i].array[1]; } #endregion int max = 1; for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (pairs[i, 0] > pairs[j, 1] && dp[i] <= dp[j]) { dp[i] = dp[j] + 1; max = Math.Max(max, dp[i]); } } } return(max); }
public void Setup() { // -9 -9 -9 1 1 1 // 0 -9 0 4 3 2 // -9 -9 -9 1 2 3 // 0 0 8 6 6 0 // 0 0 0 -2 0 0 // 0 0 1 2 4 0 _firstCase = new int[][] { new int[] { -9, -9, -9, 1, 1, 1 }, new int[] { 0, -9, 0, 4, 3, 2 }, new int[] { -9, -9, -9, 1, 2, 3 }, new int[] { 0, 0, 8, 6, 6, 0 }, new int[] { 0, 0, 0, -2, 0, 0 }, new int[] { 0, 0, 1, 2, 4, 0 } }; _solution = new TwoDArray(); // -1 -1 0 -9 -2 -2 // -2 ,-1 ,-6, -8, -2, -5 // -1 ,-1 ,-1, -2, -3, -4 // -1 ,-9 ,-2, -4, -4, -5 // -7 ,-3 ,-3, -2, -9, -9 // -1 ,-3 ,-1, -2, -4, -5 _secondCase = new int[][] { new[] { -1, -1, 0, -9, -2, -2 }, new[] { -2, -1, -6, -8, -2, -5 }, new[] { -1, -1, -1, -2, -3, -4 }, new[] { -1, -9, -2, -4, -4, -5 }, new[] { -7, -3, -3, -2, -9, -9 }, new[] { -1, -3, -1, -2, -4, -5 }, new[] { -1, -1, 0, -9, -2, -2 } }; }
static void Main(string[] args) { Console.WriteLine("Enter your choice"); int options = Convert.ToInt32(Console.ReadLine()); switch (options) { case 1: Replace aclass = new Replace(); aclass.replace(); break; case 2: coinToss bclass = new coinToss(); bclass.coins(); break; case 3: leapYear cclass = new leapYear(); cclass.leap(); break; case 4: powerTwo dclass = new powerTwo(); dclass.power(); break; case 5: factor eclass = new factor(); eclass.primes(); break; case 6: Harmonic fclass = new Harmonic(); fclass.harnum(); break; case 7: Distance gclass = new Distance(); gclass.dist(); break; case 8: windchill hclass = new windchill(); hclass.wind(); break; case 9: quadricEquation iclass = new quadricEquation(); iclass.equation(); break; case 10: sumOfThree jclass = new sumOfThree(); jclass.integer(); break; case 11: Gambler kclass = new Gambler(); kclass.Game(); break; case 12: swatch lclass = new swatch(); lclass.watch(); break; case 13: coupon mclass = new coupon(); mclass.number(); break; case 14: TwoDArray nclass = new TwoDArray(); nclass.array2D(); break; case 15: TIC_TAC_TOE oclass = new TIC_TAC_TOE(); oclass.tok(); break; } }