Advertisement
ivan_yosifov

Lines

Nov 28th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         short[] num = new short[8];
  8.         for (int i = 0; i < 8; i++)
  9.         {
  10.             num[i] = short.Parse(Console.ReadLine());
  11.         }
  12.  
  13.         short[] score = new short[9]; // store how many times a length occurs
  14.         int length = 0;
  15.         int max = 0;
  16.         int topMax = 0;
  17.  
  18.         // count 1's sequence for rows
  19.         for (int i = 0; i < 8; i++)
  20.         {
  21.             max = 0;
  22.             length = 0;
  23.             for (int j = 7; j >= 0; j--)
  24.             {
  25.                 int bit = (num[i] >> j) & 1;
  26.                
  27.                 if (bit == 1)
  28.                 {                    
  29.                     length++;
  30.                     if (max < length)
  31.                     {
  32.                         max = length;
  33.                     }
  34.                 }
  35.                 else
  36.                 {
  37.                     length = 0;
  38.                 }
  39.             }
  40.             score[max]++;
  41.             if (topMax < max)
  42.             {
  43.                 topMax = max;
  44.             }
  45.         }
  46.  
  47.         // count 1's sequence for columns
  48.         for (int i = 0; i < 8; i++)
  49.         {
  50.             max = 0;
  51.             length = 0;
  52.             for (int j = 7; j >= 0; j--)
  53.             {
  54.                 int bit = (num[j] >> i) & 1;
  55.  
  56.                 if (bit == 1)
  57.                 {
  58.                     length++;
  59.                     if (max <= length)
  60.                     {
  61.                         max = length;
  62.                     }
  63.                 }
  64.                 else
  65.                 {
  66.                     length = 0;
  67.                 }
  68.             }
  69.             score[max]++;
  70.             if (topMax <= max)
  71.             {
  72.                 topMax = max;
  73.             }
  74.         }
  75.  
  76.         if (topMax == 1)
  77.         {
  78.             score[topMax] = 1;
  79.         }
  80.         // print results
  81.         Console.WriteLine(topMax);
  82.         Console.WriteLine(score[topMax]);      
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement