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;
- namespace _04._3D_Stars
- {
- class Program
- {
- static char[, ,] cuboid;
- static Dictionary<char,int> result = new Dictionary<char,int>();
- static void Main(string[] args)
- {
- string[] dimensions = Console.ReadLine().Split(' ');
- //string[] dimensions = "7 4 3".Split(' ');
- int width = int.Parse(dimensions[0]);
- int height = int.Parse(dimensions[1]);
- int depth = int.Parse(dimensions[2]);
- cuboid = new char[depth, height, width];
- //string[] input = {
- // "BRYYYYY RYYYYGY YRYYYYY",
- // "YYYGBGY YYYYGGG YYYGGGY",
- // "RYBYGYY RYYYYGY RYBYGBB",
- // "RYBYGYY RBYYGYY RYBYGBB"
- // };
- FillCuboid(width, height, depth/*, input*/);
- FindNeighbours();
- Console.WriteLine(result.Sum(x => x.Value));
- foreach (var item in result.OrderBy(x => x.Key))
- {
- Console.WriteLine("{0} {1}",item.Key, item.Value);
- }
- }
- private static void FindNeighbours()
- {
- for (int slice = 0; slice < cuboid.GetLength(0); slice++)
- {
- for (int rows = 0; rows < cuboid.GetLength(1); rows++)
- {
- for (int cols = 0; cols < cuboid.GetLength(2); cols++)
- {
- char currentColor = cuboid[slice,rows,cols];
- int count = 1;
- //check upper cuboid
- if (rows - 1 >= 0 && cuboid[slice, rows - 1, cols] == currentColor)
- {
- count++;
- }
- else continue;
- //check downer cuboid
- if (rows + 1 < cuboid.GetLength(1) && cuboid[slice, rows + 1, cols] == currentColor)
- {
- count++;
- }
- else continue;
- //check left cuboid
- if (cols - 1 >= 0 && cuboid[slice, rows, cols-1] == currentColor)
- {
- count++;
- }
- else continue;
- //check right cuboid
- if (cols + 1 < cuboid.GetLength(2) && cuboid[slice, rows, cols+1] == currentColor)
- {
- count++;
- }
- else continue;
- //check backward cuboid
- if (slice - 1 >= 0 && cuboid[slice-1, rows, cols] == currentColor)
- {
- count++;
- }
- else continue;
- //check upward cuboid
- if (slice + 1 < cuboid.GetLength(0) && cuboid[slice+1, rows, cols] == currentColor)
- {
- count++;
- }
- else continue;
- if (count == 7)
- {
- Score(currentColor);
- }
- }
- }
- }
- }
- private static void Score(char currentColor)
- {
- if (result.ContainsKey(currentColor))
- {
- result[currentColor]++;
- }
- else
- {
- result.Add(currentColor, 1);
- }
- }
- private static void FillCuboid(int width, int height, int depth /*,string[] input*/)
- {
- for (int rows = 0; rows < height; rows++)
- {
- //string[] line = input[rows].Split(' ');
- string[] line = Console.ReadLine().Split(' ');
- int lineLength = line.Length;
- for (int slices = 0; slices < lineLength; slices++)
- {
- int slicesLength = line[slices].Length;
- for (int cols = 0; cols < slicesLength; cols++)
- {
- cuboid[slices, rows, cols] = line[slices][cols];
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement