Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- //You are given a rectangular cuboid of size W (width), H (height) and D (depth) consisting of W * H * D cubes,
- //each containing an integer number. A cuboid can be split into two sub-cuboids by slicing it over some of the planes
- //{x, y}, {x, z} or {y, z}.
- //The cuboid is given as layers of matrices holding integer numbers.
- //Your task is to write a program that finds in how many ways we can split the cuboid into two non-empty sub-cuboids
- //such that the sums of the numbers in the obtained sub-cuboids are equal.
- class Program
- {
- static void Main()
- {
- int width, height, depth;
- string[] input = Console.ReadLine().Split();
- width = int.Parse(input[0]);
- height = int.Parse(input[1]);
- depth = int.Parse(input[2]);
- int[, ,] cube = new int[height, width, depth];
- Fill(width, height, depth, cube);
- //find sums of all dimintions
- int[] sumHeight = new int[height];
- int[] sumWidth = new int[width];
- int[] sumDepth = new int[depth];
- for (int x = 0; x < height; x++)
- {
- for (int z = 0; z < depth; z++)
- {
- for (int y = 0; y < width; y++)
- {
- sumHeight[x] += cube[x, y, z];
- sumWidth[y] += cube[x, y, z];
- sumDepth[z] += cube[x, y, z];
- }
- }
- }
- CalcMatches(sumHeight, sumWidth, sumDepth);
- }
- private static void CalcMatches(int[] sumHeight, int[] sumWidth, int[] sumDepth)
- {
- int sum1 = 0, sum2 = 0;
- int count = 0;
- //width
- for (int k = 0; k < sumWidth.Length - 1; k++)
- {
- sum1 = 0;
- sum2 = 0;
- for (int i = 0; i < sumWidth.Length; i++)
- {
- if (i <= k)
- {
- sum1 += sumWidth[i];
- }
- else
- {
- sum2 += sumWidth[i];
- }
- }
- if (sum1 == sum2)
- {
- count++;
- }
- }
- //height
- for (int k = 0; k < sumHeight.Length - 1; k++)
- {
- sum1 = 0;
- sum2 = 0;
- for (int i = 0; i < sumHeight.Length; i++)
- {
- if (i <= k)
- {
- sum1 += sumHeight[i];
- }
- else
- {
- sum2 += sumHeight[i];
- }
- }
- if (sum1 == sum2)
- {
- count++;
- }
- }
- //depth
- for (int k = 0; k < sumDepth.Length - 1; k++)
- {
- sum1 = 0;
- sum2 = 0;
- for (int i = 0; i < sumDepth.Length; i++)
- {
- if (i <= k)
- {
- sum1 += sumDepth[i];
- }
- else
- {
- sum2 += sumDepth[i];
- }
- }
- if (sum1 == sum2)
- {
- count++;
- }
- }
- Console.WriteLine(count);
- }
- private static void Fill(int width, int height, int depth, int[, ,] cube)
- {
- string[] data = new string[height];
- string[] row;
- string[] cells;
- for (int x = 0; x < height; x++)
- {
- data[x] = Console.ReadLine();
- for (int z = 0; z < depth; z++)
- {
- row = data[x].Split('|');
- char[] factor = { ' ' };
- cells = row[z].Split(factor, StringSplitOptions.RemoveEmptyEntries);
- for (int y = 0; y < width; y++)
- {
- cube[x, y, z] = int.Parse(cells[y]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement