Advertisement
stefanpu

Lines

Dec 18th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.74 KB | None | 0 0
  1. using System;
  2.  
  3. class Lines
  4. {
  5.     static void Main()
  6.     {
  7.         int[,] field = new int[8, 8];
  8.         for (int row = 0; row < 8; row++)
  9.         {
  10.             int currentNumber = int.Parse(Console.ReadLine());
  11.             string binaryNumber = Convert.ToString(currentNumber, 2);
  12.             binaryNumber = binaryNumber.PadLeft(8, '0');
  13.  
  14.             for (int col = 0; col < 8; col++)
  15.             {
  16.                 switch (binaryNumber[col])
  17.                 {
  18.                     case '0': field[row, col] = 0; break;
  19.                     case '1': field[row, col] = 1; break;
  20.                     default: break;
  21.                 }
  22.             }
  23.         }
  24.  
  25.         int longest = 0;
  26.         int longestCount = 0;
  27.  
  28.         //For each bit...
  29.         for (int row = 0; row < 8; row++)
  30.         {
  31.  
  32.             //Mistake here. You never check  field[row, 7]. That is why 0000 0001 is not checked
  33.             //on the horizontal.
  34.             //What if eight numbers are 1,0,0,0,0,0,0,0 (See test 7) :
  35.             //         0000 0001
  36.             //         .........
  37.             //         0000 0000
  38.  
  39.             // First number will not be detected horizontally - outcome will be 0
  40.             // when it has to be 1.
  41.  
  42.             //In Each number.. originally col<7 : new - col < 8
  43.             for (int col = 0; col < 8; col++)
  44.             {
  45.                 int currCount = 0;
  46.                 //If new line starts.
  47.                 if (field[row, col] == 1)
  48.                 {
  49.                     //While it is the same line and index is not outside array, add to line length.
  50.                     //Original: (col+1) < 8 new: col < 8
  51.                     while ((col  < 8) && (field[row, col] == 1))
  52.                     {
  53.                         col++;
  54.                         currCount++;
  55.                     }
  56.  
  57.                     //This is code is not needed anymore.
  58.                      
  59.  
  60.                     //if ((col ) >= 8)
  61.                     //{
  62.              
  63.                     //    if ((field[row, 7] == field[row, 6]) && (field[row, 6] == 1))
  64.                     //    {
  65.                     //        currCount++;
  66.                     //    }
  67.                     //}
  68.                 }
  69.  
  70.                 if (currCount > longest)
  71.                 {
  72.                     longestCount = 1;
  73.                     longest = currCount;
  74.                 }
  75.                 else if (currCount == longest)
  76.                 {
  77.                     longestCount++;
  78.                 }
  79.  
  80.             }
  81.         }
  82.        
  83.         for (int col = 0; col < 8; col++)
  84.         {
  85.             //Mistake here. You never check  field[7,col]. Originally row < 7 : new - row < 8
  86.             for (int row = 0; row < 8; row++)
  87.             {
  88.                 int currCount = 0;
  89.                 if (field[row, col] == 1)
  90.                 {
  91.                     while (((row) < 8) && (field[row, col] == 1))
  92.                     {
  93.                         row++;
  94.                         currCount++;
  95.                     }
  96.                     //This code is not needed any more.
  97.                     //if ((row ) >= 8)
  98.                     //{
  99.                     //    if ((field[7, col] == field[6, col]) && (field[6, col] == 1))
  100.                     //    {
  101.                     //        currCount++;
  102.                     //    }
  103.                     //}
  104.                 }
  105.  
  106.                 if (currCount > longest)
  107.                 {
  108.                     longestCount = 1;
  109.                     longest = currCount;
  110.                 }
  111.                 else if (currCount == longest)
  112.                 {
  113.                     longestCount++;
  114.                 }
  115.  
  116.             }
  117.         }
  118.         Console.WriteLine(longest);
  119.         Console.WriteLine(longestCount);
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement