archangelmihail

LinesWithMatrix

Dec 4th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.37 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 Lines
  8. {
  9.     class Lines
  10.     {
  11.         static void Main()
  12.         {
  13.             //initialization
  14.             int[,] grid = new int[8, 8];
  15.             bool zero = true;
  16.             for (int row = 0; row < 8; row++)
  17.             {
  18.                 int number = int.Parse(Console.ReadLine());
  19.                 string numberToString = Convert.ToString(number, 2).PadLeft(8, '0');
  20.                 for (int col = 0; col < 8; col++)
  21.                 {
  22.                     grid[row, col] = int.Parse(numberToString[col].ToString());
  23.                     if (grid[row, col] == 1)
  24.                     {
  25.                         zero = false;
  26.                     }
  27.                 }
  28.             }
  29.             if (zero)
  30.             {
  31.                 Console.WriteLine("8");
  32.                 Console.WriteLine("16");
  33.                 return;
  34.             }
  35.             int longest = 0;
  36.             int result = 0;
  37.             //solution
  38.             for (int i = 0; i < 8; i++)
  39.             {
  40.                 for (int j = 0; j < 8; j++)
  41.                 {
  42.                     int length = 0;
  43.                     if (grid[i,j] == 1)
  44.                     {
  45.                         length = 1;
  46.                         grid[i, j] = 0;
  47.                         if (i+1<8)
  48.                         {
  49.                             for (int row = i + 1; row < 8; row++)
  50.                             {
  51.                                 if (grid[row, j] == 1)
  52.                                 {
  53.                                     length++;
  54.                                 }
  55.                                 else
  56.                                 {
  57.                                     break;
  58.                                 }
  59.                             }
  60.                             if (length == longest)
  61.                             {
  62.                                 result++;
  63.                             }
  64.                             else if (length > longest)
  65.                             {
  66.                                 result = 1;
  67.                                 longest = length;
  68.                             }
  69.                         }
  70.                         length = 1;
  71.                        
  72.                         if (j+1<8)
  73.                         {
  74.                             for (int cow = j + 1; cow < 8; cow++)
  75.                             {
  76.                                 if (grid[i,cow] == 1)
  77.                                 {
  78.                                     length++;
  79.                                 }
  80.                                 else
  81.                                 {
  82.                                     break;
  83.                                 }
  84.                             }
  85.                             if (length == longest)
  86.                             {
  87.                                 result++;
  88.                             }
  89.                             else if( length >longest)
  90.                             {
  91.                                 result = 1;
  92.                                 longest = length;
  93.                             }
  94.                         }
  95.                     }
  96.                 }
  97.             }
  98.             // output
  99.             Console.WriteLine(longest);
  100.             Console.WriteLine(result);
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment