archangelmihail

LinesBitwise

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