Advertisement
Guest User

Lines100percent

a guest
Nov 28th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         //read input data
  8.         byte[] numbers = new byte[8];
  9.         for (int i = 0; i < 8; i++)
  10.         {
  11.             numbers[i] = byte.Parse(Console.ReadLine());
  12.         }
  13.  
  14.         //some variables to store data
  15.         byte currentLine = 0;
  16.         byte longestLine = 0;
  17.         byte longestLineCount = 0;
  18.  
  19.         //check lines in colums
  20.         for (int col = 0; col < 8; col++)
  21.         {
  22.             for (int i = 0; i < 8; i++)
  23.             {
  24.                 byte mask = (byte)((numbers[i] >> col) & 1);
  25.                 if (mask == 1) currentLine++;
  26.                 if (mask == 0 | i == 7)
  27.                 {
  28.                     if (currentLine == longestLine) longestLineCount++;
  29.                     if (currentLine > longestLine)
  30.                     {
  31.                         longestLine = currentLine;
  32.                         longestLineCount = 1;
  33.                         currentLine = 0;
  34.                     }
  35.                     currentLine = 0;
  36.                 }
  37.             }
  38.         }
  39.  
  40.         //check lines in rows
  41.         for (int row = 0; row < 8; row++)
  42.         {
  43.             for (int i = 0; i < 8; i++)
  44.             {
  45.                 byte mask = (byte)((numbers[row] >> i) & 1);
  46.                 if (mask == 1) currentLine++;
  47.                 if (mask == 0 | i == 7)
  48.                 {
  49.                     if (currentLine == longestLine) longestLineCount++;
  50.                     if (currentLine > longestLine)
  51.                     {
  52.                         longestLine = currentLine;
  53.                         longestLineCount = 1;
  54.                         currentLine = 0;
  55.                     }
  56.                     currentLine = 0;
  57.                 }
  58.             }
  59.         }
  60.  
  61.         if (longestLine == 1) longestLineCount = (byte)(longestLineCount / 2);
  62.         Console.WriteLine(longestLine);
  63.         Console.WriteLine(longestLineCount);
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement