Advertisement
sylviapsh

Cuboid Slices 3D

Feb 3rd, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2.  
  3. class Slices3D
  4. {
  5.   static void Main()
  6.   {
  7.     int width, height, depth;
  8.  
  9.     string dimensionsStr = Console.ReadLine();
  10.     string[] dimensions = dimensionsStr.Split(' ');
  11.     width = int.Parse(dimensions[0]);
  12.     height = int.Parse(dimensions[1]);
  13.     depth = int.Parse(dimensions[2]);
  14.     int [,,] cuboid = new int [width,height, depth];
  15.     long totalSum = 0;
  16.  
  17.     for (int h = 0; h < height; h++)
  18.     {
  19.       string valuesStr = Console.ReadLine();
  20.       string[] valuesByDimension = valuesStr.Split('|');
  21.       for (int d = 0; d < depth; d++)
  22.       {
  23.         char[] delimiter = { ' ' };
  24.         string[] values = valuesByDimension[d].Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
  25.         for (int w = 0; w < width; w++)
  26.         {
  27.           cuboid[w, h, d] = int.Parse(values[w]);
  28.           totalSum += cuboid[w, h, d];
  29.         }
  30.       }
  31.  
  32.     }
  33.  
  34.     long currentSum = 0;
  35.     int counter = 0;
  36.     for (int w = 0; w < width-1; w++)
  37.     {
  38.       for (int h = 0; h < height; h++)
  39.       {
  40.         for (int d = 0; d < depth; d++)
  41.         {
  42.           currentSum += cuboid[w, h, d];
  43.         }
  44.       }
  45.       if (currentSum + currentSum == totalSum)
  46.       {
  47.         counter++;
  48.       }
  49.     }
  50.  
  51.     currentSum = 0;
  52.     for (int h = 0; h < height-1; h++)
  53.     {
  54.       for (int w = 0; w < width; w++)
  55.       {
  56.         for (int d = 0; d < depth; d++)
  57.         {
  58.           currentSum += cuboid[w, h, d];
  59.         }
  60.       }
  61.       if (currentSum + currentSum == totalSum)
  62.       {
  63.         counter++;
  64.       }
  65.     }
  66.  
  67.     currentSum = 0;
  68.     for (int d = 0; d < depth-1; d++)
  69.     {
  70.       for (int h = 0; h < height; h++)
  71.       {
  72.         for (int w = 0; w < width; w++)
  73.         {
  74.           currentSum += cuboid[w, h, d];
  75.         }
  76.       }
  77.       if (currentSum + currentSum == totalSum)
  78.       {
  79.         counter++;
  80.       }
  81.     }
  82.  
  83.       Console.WriteLine(counter);
  84.    
  85.   }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement