Advertisement
Asinka

05. Lines (7 Dec 2011 Morning)

Dec 26th, 2012
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4.  
  5. class Lines
  6. {
  7.     static void Main()
  8.     {
  9.         byte[] countVertical = new byte[8];
  10.         byte previousBit = 0;
  11.         byte lenght = 0;
  12.         byte countHorizontal = 0;
  13.         byte result = 0;
  14.        
  15.  
  16.  
  17.         for (byte i = 0; i < 8; i++)
  18.         {
  19.             countHorizontal = 0;
  20.             byte number = byte.Parse(Console.ReadLine());
  21.             for (int j = 0; j < 8; j++)
  22.             {
  23.                 byte mask = (byte)(1 << j);
  24.                 byte bit = (byte)(number & mask);
  25.                 bit = (byte)(bit >> j);
  26.  
  27.                 //Horizontal lines
  28.                 if (bit == 1)
  29.                 {
  30.                     countHorizontal++;
  31.                     if (countHorizontal > lenght)
  32.                     {
  33.                         lenght = countHorizontal;
  34.                         result = 0;
  35.  
  36.                     }
  37.                     previousBit = bit;
  38.                     if (j == 7 && countHorizontal == lenght)
  39.                     {
  40.                         result++;
  41.                     }
  42.                 }
  43.                 else
  44.                 {
  45.                     if (bit != previousBit && countHorizontal == lenght)
  46.                     {
  47.                         result++;
  48.                     }
  49.                     countHorizontal = 0;
  50.                 }
  51.  
  52.                 //Vertikal lines
  53.                 if (bit == 1)
  54.                 {
  55.                     countVertical[j] ++;
  56.                    
  57.                     if (countVertical[j] > lenght)
  58.                     {
  59.                         lenght = countVertical[j];
  60.                         result = 0;
  61.                     }
  62.                     if (i == 7 && countVertical[j] == lenght && lenght != 1)
  63.                     {
  64.                         result++;
  65.                     }
  66.                 }
  67.                 else
  68.                 {
  69.                     if (bit != countVertical[j] && countVertical[j] == lenght && lenght != 1)
  70.                     {
  71.                         result++;
  72.                     }
  73.                     countVertical[j] = 0;
  74.                 }              
  75.             }
  76.         }
  77.         Console.WriteLine(lenght);
  78.         Console.WriteLine(result);
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement