Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Slices
- {
- static void Main()
- {
- string inputMatrixString = Console.ReadLine(); // "2 2 2"; // Console.ReadLine();
- string[] inputAsArray = inputMatrixString.Split();
- int matrixWidth = int.Parse(inputAsArray[0]);
- int matrixHeigth = int.Parse(inputAsArray[1]);
- int matrixDepth = int.Parse(inputAsArray[2]);
- string[] tempLines = new string[matrixHeigth];
- //tempLines[0] = "1 2 | 3 4"; //
- //tempLines[1] = "5 6 | 7 8"; //
- for (int i = 0; i < matrixHeigth; i++)
- {
- tempLines[i] = Console.ReadLine();
- }
- int[,,] matrix = ReadTheInput(matrixWidth, matrixHeigth, matrixDepth, tempLines);
- int equalSumsW = CountingEqualSumsW(matrix);
- int equalSumsH = CountingEqualSumsH(matrix);
- int equalSumsD = CountingEqualSumsD(matrix);
- Console.WriteLine(equalSumsW + equalSumsH + equalSumsD);
- }
- private static int CountingEqualSumsD(int[, ,] matrix)
- {
- int sumOne = 0;
- int sumTwo = 0;
- int countEqualSums = 0;
- for (int i = 0; i < matrix.GetLength(2); i++)
- {
- for (int j = 0; j < i + 1; j++)
- {
- if (j == matrix.GetLength(2) - 1)
- {
- sumOne = int.MinValue;
- break;
- }
- for (int h = 0; h < matrix.GetLength(0); h++)
- {
- for (int d = 0; d < matrix.GetLength(1); d++)
- {
- sumOne = sumOne + matrix[h, d, j];
- }
- }
- }
- for (int j = i + 1; j < matrix.GetLength(2); j++)
- {
- for (int h = 0; h < matrix.GetLength(0); h++)
- {
- for (int d = 0; d < matrix.GetLength(1); d++)
- {
- sumTwo = sumTwo + matrix[h, d, j];
- }
- }
- }
- if (sumOne == sumTwo)
- {
- countEqualSums++;
- sumTwo = 0;
- sumOne = 0;
- }
- else
- {
- sumTwo = 0;
- sumOne = 0;
- continue;
- }
- }
- return countEqualSums;
- }
- private static int CountingEqualSumsH(int[, ,] matrix)
- {
- int sumOne = 0;
- int sumTwo = 0;
- int countEqualSums = 0;
- for (int i = 0; i < matrix.GetLength(1); i++)
- {
- for (int j = 0; j < i + 1; j++)
- {
- if (j == matrix.GetLength(1) - 1)
- {
- sumOne = int.MinValue;
- break;
- }
- for (int h = 0; h < matrix.GetLength(0); h++)
- {
- for (int d = 0; d < matrix.GetLength(2); d++)
- {
- sumOne = sumOne + matrix[h, j, d];
- }
- }
- }
- for (int j = i + 1; j < matrix.GetLength(1); j++)
- {
- for (int h = 0; h < matrix.GetLength(0); h++)
- {
- for (int d = 0; d < matrix.GetLength(2); d++)
- {
- sumTwo = sumTwo + matrix[h, j, d];
- }
- }
- }
- if (sumOne == sumTwo)
- {
- countEqualSums++;
- sumTwo = 0;
- sumOne = 0;
- }
- else
- {
- sumTwo = 0;
- sumOne = 0;
- continue;
- }
- }
- return countEqualSums;
- }
- private static int CountingEqualSumsW(int[, ,] matrix)
- {
- int sumOne = 0;
- int sumTwo = 0;
- int countEqualSums = 0;
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- for (int j = 0; j < i + 1; j++)
- {
- if (j == matrix.GetLength(0) - 1)
- {
- sumOne = int.MinValue;
- break;
- }
- for (int h = 0; h < matrix.GetLength(1); h++)
- {
- for (int d = 0; d < matrix.GetLength(2); d++)
- {
- sumOne = sumOne + matrix[j, h, d];
- }
- }
- }
- for (int j = i + 1; j < matrix.GetLength(0); j++)
- {
- for (int h = 0; h < matrix.GetLength(1); h++)
- {
- for (int d = 0; d < matrix.GetLength(2); d++)
- {
- sumTwo = sumTwo + matrix[j, h, d];
- }
- }
- }
- if (sumOne == sumTwo)
- {
- countEqualSums++;
- sumTwo = 0;
- sumOne = 0;
- }
- else
- {
- sumTwo = 0;
- sumOne = 0;
- continue;
- }
- }
- return countEqualSums;
- }
- private static int[,,] ReadTheInput(int matrixWidth, int matrixHeigth, int matrixDepth, string[] tempLines)
- {
- int[,,] matrix = new int[matrixWidth, matrixHeigth, matrixDepth];
- for (int i = 0; i < matrix.GetLength(1); i++)
- {
- string[] depthsStr = tempLines[i].Split('|');
- for (int j = 0; j < matrix.GetLength(2); j++)
- {
- string[] widthStr = depthsStr[j].Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
- for (int k = 0; k < matrix.GetLength(0); k++)
- {
- matrix[k, i, j] = int.Parse(widthStr[k].Trim());
- }
- }
- }
- return matrix;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement