Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Lines
- {
- static void Main()
- {
- int[,] field = new int[8, 8];
- for (int row = 0; row < 8; row++)
- {
- int currentNumber = int.Parse(Console.ReadLine());
- string binaryNumber = Convert.ToString(currentNumber, 2);
- binaryNumber = binaryNumber.PadLeft(8, '0');
- for (int col = 0; col < 8; col++)
- {
- switch (binaryNumber[col])
- {
- case '0': field[row, col] = 0; break;
- case '1': field[row, col] = 1; break;
- default: break;
- }
- }
- }
- int longest = 0;
- int longestCount = 0;
- //For each bit...
- for (int row = 0; row < 8; row++)
- {
- //Mistake here. You never check field[row, 7]. That is why 0000 0001 is not checked
- //on the horizontal.
- //What if eight numbers are 1,0,0,0,0,0,0,0 (See test 7) :
- // 0000 0001
- // .........
- // 0000 0000
- // First number will not be detected horizontally - outcome will be 0
- // when it has to be 1.
- //In Each number.. originally col<7 : new - col < 8
- for (int col = 0; col < 8; col++)
- {
- int currCount = 0;
- //If new line starts.
- if (field[row, col] == 1)
- {
- //While it is the same line and index is not outside array, add to line length.
- //Original: (col+1) < 8 new: col < 8
- while ((col < 8) && (field[row, col] == 1))
- {
- col++;
- currCount++;
- }
- //This is code is not needed anymore.
- //if ((col ) >= 8)
- //{
- // if ((field[row, 7] == field[row, 6]) && (field[row, 6] == 1))
- // {
- // currCount++;
- // }
- //}
- }
- if (currCount > longest)
- {
- longestCount = 1;
- longest = currCount;
- }
- else if (currCount == longest)
- {
- longestCount++;
- }
- }
- }
- for (int col = 0; col < 8; col++)
- {
- //Mistake here. You never check field[7,col]. Originally row < 7 : new - row < 8
- for (int row = 0; row < 8; row++)
- {
- int currCount = 0;
- if (field[row, col] == 1)
- {
- while (((row) < 8) && (field[row, col] == 1))
- {
- row++;
- currCount++;
- }
- //This code is not needed any more.
- //if ((row ) >= 8)
- //{
- // if ((field[7, col] == field[6, col]) && (field[6, col] == 1))
- // {
- // currCount++;
- // }
- //}
- }
- if (currCount > longest)
- {
- longestCount = 1;
- longest = currCount;
- }
- else if (currCount == longest)
- {
- longestCount++;
- }
- }
- }
- Console.WriteLine(longest);
- Console.WriteLine(longestCount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement