Advertisement
Guest User

Untitled

a guest
Sep 9th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _3DLines
  8. {
  9.     class Program
  10.     {
  11.         static int width;
  12.         static int height;
  13.         static int depth;
  14.         static char[, ,] matrix;
  15.         static char curChar;
  16.         static int curd;
  17.         static int curh;
  18.         static int curw;
  19.         static SortedDictionary<int,long> result = new SortedDictionary<int,long>();
  20.  
  21.         static void Main(string[] args)
  22.         {
  23.             ReadInput();
  24.             AssignMatrix();
  25.             CheckForLines();
  26.             int max = 0;
  27.             foreach (var item in result)
  28.             {
  29.                 if (item.Key > max)
  30.                 {
  31.                     max = item.Key;
  32.                 }
  33.             }
  34.             if (result.Count == 0)
  35.             {
  36.                 Console.WriteLine(-1);
  37.             }
  38.             else
  39.             {
  40.                 Console.WriteLine(result.Keys.Last() + 1 + " " + result.Values.Last());
  41.             }
  42.         }
  43.  
  44.         static void CheckForLines()
  45.         {
  46.             for (int w = 0; w < width; w++)
  47.             {
  48.                 for (int h = 0; h < height; h++)
  49.                 {
  50.                     for (int d = 0; d < depth; d++)
  51.                     {
  52.                         curChar = matrix[w, h, d];
  53.                         curd = d;
  54.                         curh = h;
  55.                         curw = w;
  56.  
  57.                         HeightLinePlus();
  58.  
  59.                         //HeightLineMinus();
  60.  
  61.                         WidthLinePlus();
  62.  
  63.                        // WidthLineMinus();
  64.  
  65.                         DepthLinePlus();
  66.  
  67.                       //  DepthLineMinus();
  68.  
  69.                     }
  70.                 }
  71.             }
  72.         }
  73.  
  74.         private static void HeightLinePlus()
  75.         {
  76.             int times = 0;
  77.             int curheight = curh;
  78.             int curdepth = curd;
  79.             int curwidth = curw;
  80.  
  81.             while (curheight < height - 1)
  82.             {
  83.                 curheight++;
  84.                 if (matrix[curwidth, curheight, curdepth] == curChar)
  85.                 {
  86.                     times++;
  87.                 }
  88.             }
  89.  
  90.             if (result.ContainsKey(times))
  91.             {
  92.                 result[times] += (long)1;
  93.             }
  94.  
  95.             else if (times != 0)
  96.             {
  97.                 result.Add(times, (long)1);
  98.             }
  99.  
  100.             times = 0;
  101.             curheight = curh;
  102.             curdepth = curd;
  103.             curwidth = curw;
  104.  
  105.             while (curheight < height - 1 && curdepth < depth - 1)
  106.             {
  107.                 curheight++;
  108.                 curdepth++;
  109.                 if (matrix[curwidth, curheight, curdepth] == curChar)
  110.                 {
  111.                     times++;
  112.                 }
  113.             }
  114.  
  115.             if (result.ContainsKey(times))
  116.             {
  117.                 result[times] += (long)1;
  118.             }
  119.             else if (times != 0)
  120.             {
  121.                 result.Add(times, (long)1);
  122.             }
  123.  
  124.             times = 0;
  125.             curheight = curh;
  126.             curdepth = curd;
  127.             curwidth = curw;
  128.  
  129.             while (curheight < height - 1 && curwidth < width - 1)
  130.             {
  131.                 curheight++;
  132.                 curwidth++;
  133.                 if (matrix[curwidth, curheight, curdepth] == curChar)
  134.                 {
  135.                     times++;
  136.                 }
  137.             }
  138.  
  139.             if (result.ContainsKey(times))
  140.             {
  141.                 result[times] += (long)1;
  142.             }
  143.  
  144.             else if (times != 0)
  145.             {
  146.                 result.Add(times, (long)1);
  147.             }
  148.  
  149.             //times = 0;
  150.             //curheight = curh;
  151.             //curdepth = curd;
  152.             //curwidth = curw;
  153.  
  154.             //while (curheight < height - 1 && curwidth < width - 1 && curdepth < depth - 1)
  155.             //{
  156.             //    curheight++;
  157.             //    curwidth++;
  158.             //    curdepth++;
  159.             //    if (matrix[curwidth, curheight, curdepth] == curChar)
  160.             //    {
  161.             //        times++;
  162.             //    }
  163.             //}
  164.  
  165.             //if (result.ContainsKey(times))
  166.             //{
  167.             //    result[times] += (long)1;
  168.             //}
  169.  
  170.             //else if (times != 0)
  171.             //{
  172.             //    result.Add(times, (long)1);
  173.             //}
  174.         }
  175.  
  176.         private static void DepthLinePlus()
  177.         {
  178.             int times = 0;
  179.             int curheight = curh;
  180.             int curdepth = curd;
  181.             int curwidth = curw;
  182.  
  183.             while (curdepth < depth - 1)
  184.             {
  185.                 curdepth++;
  186.                 if (matrix[curwidth, curheight, curdepth] == curChar)
  187.                 {
  188.                     times++;
  189.                 }
  190.             }
  191.  
  192.             if (result.ContainsKey(times))
  193.             {
  194.                 result[times] += (long)1;
  195.             }
  196.  
  197.             else if (times != 0)
  198.             {
  199.                 result.Add(times, (long)1);
  200.             }
  201.  
  202.             times = 0;
  203.             curheight = curh;
  204.             curdepth = curd;
  205.             curwidth = curw;
  206.  
  207.             while (curheight < height - 1 && curdepth < depth - 1)
  208.             {
  209.                 curheight++;
  210.                 curdepth++;
  211.                 if (matrix[curwidth, curheight, curdepth] == curChar)
  212.                 {
  213.                     times++;
  214.                 }
  215.             }
  216.  
  217.             if (result.ContainsKey(times))
  218.             {
  219.                 result[times] += (long)1;
  220.             }
  221.             else if (times != 0)
  222.             {
  223.                 result.Add(times, (long)1);
  224.             }
  225.  
  226.             times = 0;
  227.             curheight = curh;
  228.             curdepth = curd;
  229.             curwidth = curw;
  230.  
  231.             while (curdepth < depth - 1 && curwidth < width - 1)
  232.             {
  233.                 curdepth++;
  234.                 curwidth++;
  235.                 if (matrix[curwidth, curheight, curdepth] == curChar)
  236.                 {
  237.                     times++;
  238.                 }
  239.             }
  240.  
  241.             if (result.ContainsKey(times))
  242.             {
  243.                 result[times] += (long)1;
  244.             }
  245.  
  246.             else if (times != 0)
  247.             {
  248.                 result.Add(times, (long)1);
  249.             }
  250.  
  251.             //times = 0;
  252.             //curheight = curh;
  253.             //curdepth = curd;
  254.             //curwidth = curw;
  255.  
  256.             //while (curheight < height - 1 && curwidth < width - 1 && curdepth < depth - 1)
  257.             //{
  258.             //    curheight++;
  259.             //    curwidth++;
  260.             //    curdepth++;
  261.             //    if (matrix[curwidth, curheight, curdepth] == curChar)
  262.             //    {
  263.             //        times++;
  264.             //    }
  265.             //}
  266.  
  267.             //if (result.ContainsKey(times))
  268.             //{
  269.             //    result[times] += (long)1;
  270.             //}
  271.  
  272.             //else if (times != 0)
  273.             //{
  274.             //    result.Add(times, (long)1);
  275.             //}
  276.         }
  277.  
  278.         private static void WidthLinePlus()
  279.         {
  280.             int times = 0;
  281.             int curheight = curh;
  282.             int curdepth = curd;
  283.             int curwidth = curw;
  284.  
  285.             while (curwidth < width - 1)
  286.             {
  287.                 curwidth++;
  288.                 if (matrix[curwidth, curheight, curdepth] == curChar)
  289.                 {
  290.                     times++;
  291.                 }
  292.             }
  293.  
  294.             if (result.ContainsKey(times))
  295.             {
  296.                 result[times] += (long)1;
  297.             }
  298.  
  299.             else if (times != 0)
  300.             {
  301.                 result.Add(times, (long)1);
  302.             }
  303.  
  304.             times = 0;
  305.             curheight = curh;
  306.             curdepth = curd;
  307.             curwidth = curw;
  308.  
  309.             while (curwidth < width - 1 && curdepth < depth - 1)
  310.             {
  311.                 curwidth++;
  312.                 curdepth++;
  313.                 if (matrix[curwidth, curheight, curdepth] == curChar)
  314.                 {
  315.                     times++;
  316.                 }
  317.             }
  318.  
  319.             if (result.ContainsKey(times))
  320.             {
  321.                 result[times] += (long)1;
  322.             }
  323.             else if (times != 0)
  324.             {
  325.                 result.Add(times, (long)1);
  326.             }
  327.  
  328.             times = 0;
  329.             curheight = curh;
  330.             curdepth = curd;
  331.             curwidth = curw;
  332.  
  333.             while (curheight < height - 1 && curwidth < width - 1)
  334.             {
  335.                 curheight++;
  336.                 curwidth++;
  337.                 if (matrix[curwidth, curheight, curdepth] == curChar)
  338.                 {
  339.                     times++;
  340.                 }
  341.             }
  342.  
  343.             if (result.ContainsKey(times))
  344.             {
  345.                 result[times] += (long)1;
  346.             }
  347.  
  348.             else if (times != 0)
  349.             {
  350.                 result.Add(times, (long)1);
  351.             }
  352.  
  353.             //times = 0;
  354.             //curheight = curh;
  355.             //curdepth = curd;
  356.             //curwidth = curw;
  357.  
  358.             //while (curheight < height - 1 && curwidth < width - 1 && curdepth < depth - 1)
  359.             //{
  360.             //    curheight++;
  361.             //    curwidth++;
  362.             //    curdepth++;
  363.             //    if (matrix[curwidth, curheight, curdepth] == curChar)
  364.             //    {
  365.             //        times++;
  366.             //    }
  367.             //}
  368.  
  369.             //if (result.ContainsKey(times))
  370.             //{
  371.             //    result[times] += (long)1;
  372.             //}
  373.  
  374.             //else if (times != 0)
  375.             //{
  376.             //    result.Add(times, (long)1);
  377.             //}
  378.         }
  379.  
  380.         static void AssignMatrix()
  381.         {
  382.             for (int h = 0; h < height; h++)
  383.             {
  384.                 string[] cubes = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  385.                 for (int d = 0; d < depth; d++)
  386.                 {
  387.                     for (int w = 0; w < width; w++)
  388.                     {
  389.                         matrix[w, h, d] = cubes[d][w];
  390.                     }
  391.                 }
  392.             }
  393.         }
  394.  
  395.         static void ReadInput()
  396.         {
  397.             string[] constraints = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  398.             width = int.Parse(constraints[0]);
  399.             height = int.Parse(constraints[1]);
  400.             depth = int.Parse(constraints[2]);
  401.             matrix = new char[width, height, depth];
  402.         }
  403.     }
  404. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement