Click here to Skip to main content
15,916,293 members
Home / Discussions / C#
   

C#

 
QuestionNeed some help with active MDI in a tabcontrol Pin
deaddog420127-Mar-09 15:05
deaddog420127-Mar-09 15:05 
AnswerRe: Need some help with active MDI in a tabcontrol Pin
Henry Minute28-Mar-09 11:07
Henry Minute28-Mar-09 11:07 
GeneralRe: Need some help with active MDI in a tabcontrol Pin
deaddog420129-Mar-09 7:53
deaddog420129-Mar-09 7:53 
GeneralRe: Need some help with active MDI in a tabcontrol Pin
deaddog420129-Mar-09 8:21
deaddog420129-Mar-09 8:21 
GeneralRe: Need some help with active MDI in a tabcontrol Pin
Henry Minute29-Mar-09 12:16
Henry Minute29-Mar-09 12:16 
Questionnotification ballon tip Pin
AlexPizzano27-Mar-09 14:53
AlexPizzano27-Mar-09 14:53 
AnswerRe: notification ballon tip Pin
quacks_a_lot28-Mar-09 10:09
quacks_a_lot28-Mar-09 10:09 
QuestionSubmatrix problem Pin
maxflair27-Mar-09 14:42
maxflair27-Mar-09 14:42 
Hello everyone, I have to find the biggest rectangle(square) in a matrix which holds only even numbers.
If I have normal rectangle with even numbers my code is working, but if I have some strange figure like two rectangles in one my code fails.
Please anyone who have done something similar before to give me a clue how to get this rectangle.
I am not very sure is it my post for here, so if its not please excuse me.
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EvenNumberMatrix
{
    class EvenNumbers
    {
        //Exaple of working array
        /*public static int[,] givenArray ={
                                   {5,2,6,8,5,9},
                                   {7,5,3,2,4,7},
                                   {9,6,3,6,4,3},
                                   {8,5,3,6,2,2},
                                   {9,6,3,7,4,7},
                                   {8,5,6,2,2,5}
                               };
         */
        //Not working array
        public static int[,] givenArray ={
                                   {5,2,6,8,5,9},
                                   {7,5,3,2,4,7},
                                   {9,6,3,6,4,2},
                                   {8,5,3,6,2,2},
                                   {9,6,3,7,4,7},
                                   {8,5,6,2,2,5}
                               };
        public static int maxCol = 0, maxRow = 0;
        //temp array to make all odd numbers zeros
        public static int[,] tempGivenArray;
        static void PrintArray(int[,] a)
        {
            for (int x = 0; x < a.GetLength(0); x++)
            {
                for (int y = 0; y < a.GetLength(1); y++)
                {
                    if (a[x, y] != 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                    }
                    else
                        Console.ForegroundColor = ConsoleColor.Gray;
                    Console.Write(a[x, y] + " ");
                }
                Console.WriteLine();
            }
        }

        static void Main(string[] args)
        {
            int number = 6; int countRows = 0, countCollums = 0, x, y;

            tempGivenArray = new int[number, number];
            // zapisvam 4etnite 4isla v nov masiv samo s nuli
            for (int i = 0; i < number - 1; i++)
            {
                for (int j = 0; j < number - 1; j++)
                {
                    if (givenArray[i, j] % 2 == 0 &&
                        givenArray[i + 1, j] % 2 == 0 &&
                        givenArray[i, j + 1] % 2 == 0 &&
                        givenArray[i + 1, j + 1] % 2 == 0)
                    {
                        tempGivenArray[i, j] = givenArray[i, j];
                        tempGivenArray[i + 1, j] = givenArray[i + 1, j];
                        tempGivenArray[i, j + 1] = givenArray[i, j + 1];
                        tempGivenArray[i + 1, j + 1] = givenArray[i + 1, j + 1];
                    }
                }
            }
            for (int i = 0; i < number - 1; i++)
            {
                for (int j = 0; j < number - 1; j++)
                {
                    x = i; y = j;
                    //loop to check if in a current row even numbers 
                    while (tempGivenArray[x, y] > 0)
                    {
                        x++;
                        countRows++;
                        if (countRows > maxRow)
                            maxRow = countRows;//maxRow holds positions for even number in row
                        if (x > number - 1)//if out of array
                            break;
                    }
                    x = i; y = j; countRows = 0;
                    while (tempGivenArray[x, y] > 0)
                    {
                        y++;
                        countCollums++;
                        if (countCollums > maxCol)//maxCol holds positions for even number in collum
                            maxCol = countCollums;
                        if (y > number - 1)//if out of array 
                            break;
                    }
                    countCollums = 0;

                }
            }
            PrintArray(tempGivenArray);
            Console.WriteLine("The biggest rectangle with even numbers is: "+maxCol * maxRow+" positions!");

        }

    }
}

Thank you very much in advance
AnswerRe: Submatrix problem Pin
Luc Pattyn27-Mar-09 20:55
sitebuilderLuc Pattyn27-Mar-09 20:55 
GeneralRe: Submatrix problem Pin
maxflair27-Mar-09 23:16
maxflair27-Mar-09 23:16 
QuestionWPF listbox bug? Pin
Viplex27-Mar-09 14:11
Viplex27-Mar-09 14:11 
Answerpls ignore my question Pin
Viplex27-Mar-09 14:29
Viplex27-Mar-09 14:29 
QuestionCross Page Postback Pin
stormcandi27-Mar-09 11:31
stormcandi27-Mar-09 11:31 
QuestionSearching words in a matrix Pin
nike_arh27-Mar-09 10:42
nike_arh27-Mar-09 10:42 
AnswerRe: Searching words in a matrix Pin
Deresen27-Mar-09 12:02
Deresen27-Mar-09 12:02 
GeneralRe: Searching words in a matrix Pin
nike_arh27-Mar-09 12:32
nike_arh27-Mar-09 12:32 
AnswerRe: Searching words in a matrix Pin
Luc Pattyn27-Mar-09 21:21
sitebuilderLuc Pattyn27-Mar-09 21:21 
GeneralRe: Searching words in a matrix Pin
nike_arh27-Mar-09 23:27
nike_arh27-Mar-09 23:27 
AnswerRe: Searching words in a matrix Pin
nike_arh28-Mar-09 6:56
nike_arh28-Mar-09 6:56 
QuestionDragging and resizing blocks thread Pin
invader8227-Mar-09 9:40
invader8227-Mar-09 9:40 
AnswerRe: Dragging and resizing blocks thread Pin
Dave Kreskowiak27-Mar-09 12:08
mveDave Kreskowiak27-Mar-09 12:08 
GeneralRe: Dragging and resizing blocks thread Pin
invader8229-Mar-09 23:05
invader8229-Mar-09 23:05 
AnswerRe: Dragging and resizing blocks thread Pin
Alan N28-Mar-09 7:48
Alan N28-Mar-09 7:48 
GeneralRe: Dragging and resizing blocks thread Pin
invader8229-Mar-09 23:11
invader8229-Mar-09 23:11 
QuestionUserPrinicipal Enabled... Nullable type? Pin
Jacob Dixon27-Mar-09 9:18
Jacob Dixon27-Mar-09 9:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.