C# 행렬 작업

5823 단어 C#
아무 말도 안 하고 코드로 바로 갈게요.
주 창 함수
private static ABCMatrix m_ABCMatrixTest = new ABCMatrix();

        Random ran = new Random(); //    



        private void btnJudgeABCMatrix_Click(object sender, EventArgs e)

        {

            try

            {

                GetABCMatrix("true");

                MessageBox.Show(IsExist(5, m_ABCMatrixTest).ToString());

            }

            catch (Exception)

            {



            }

        }



        private void btnGetWrongMartix_Click(object sender, EventArgs e)

        {

            try

            {

                GetABCMatrix("false");

                MessageBox.Show(IsExist(5, m_ABCMatrixTest).ToString());

            }

            catch (Exception ee)

            {



            }

        }



        /// <summary>

        ///   ABCMatrix

        /// </summary>

        /// <param name="strMatrixState">    </param>

        private void GetABCMatrix(string strMatrixState)

        {

            string strMatrixName = "";

            int iSize = 0;

            try

            {

                iSize = Convert.ToInt32(txtMatrixSize.Text);

                strMatrixName = txtMatrixName.Text;

            }

            catch (Exception)

            {

                iSize = 5;

            }

            if (strMatrixName == "" || strMatrixName == null)

            {

                strMatrixName = "    ";

            }

            ABCMatrix abcMatrixTest = new ABCMatrix(iSize, iSize, strMatrixName);

            int[,] iTestMatrix = abcMatrixTest.Members;

            if (strMatrixState == "true")

            {

                for (int i = 0; i < iSize; i++)

                {

                    for (int j = 0; j < iSize; j++)

                    {

                        iTestMatrix[j, i] = i + iSize * j;

                    }

                }

            }

            else

            {

                for (int i = 0; i < iSize; i++)

                {

                    for (int j = 0; j < iSize; j++)

                    {

                        iTestMatrix[j, i] = ran.Next(0, 100);

                    }

                }

                iTestMatrix[0, 0] = 2; iTestMatrix[0, 1] = 1;

            }

            m_ABCMatrixTest = abcMatrixTest;

            txtABCMatrix.Text = MatrixPrint(abcMatrixTest);

        }



        /// <summary>

        ///   ABCMartix

        /// </summary>

        /// <param name="iSize">    </param>

        /// <param name="matrix">    </param>

        /// <returns></returns>

        public bool IsExist(int iSize, ABCMatrix matrix)

        {

            int[,] iTestMatrix = matrix.Members;

            for (int i=0;i<iSize ;i++ )

            {

                for (int j = 0; j < iSize; j++)

                {

                    if (i + 1 < iSize && iTestMatrix[j, i] >= iTestMatrix[j, i + 1])

                    {

                        return false;

                    }

                    if (j + 1 < iSize && iTestMatrix[j, i] >= iTestMatrix[j + 1, i])

                    {

                        return false;

                    }

                }

            }

            return true;

        }

        

        /// <summary>

        ///     

        /// </summary>

        /// <param name="Ma">    </param>

        /// <returns>       </returns>

        public static string MatrixPrint(ABCMatrix Ma)

        {

            string s;

            s = Ma.Name + ":\r
"; int m = Ma.getM; int n = Ma.getN; int[,] a = Ma.Members; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { s += a[i, j].ToString() + "\t"; } s += "\r
"; } return s; }

  
ABCMatrix.cs
int[,] abcMartix;

        //m n 

        int iRow, iLine;

        string name;



        public ABCMatrix()

        {



        }



        /// <summary>

        ///        

        /// </summary>

        /// <param name="am">  </param>

        /// <param name="an">  </param>

        public ABCMatrix(int am, int an)

        {

            iRow = am;

            iLine = an;

            abcMartix = new int[iRow, iLine];

            name = "Result";

        }



        /// <summary>

        ///        

        /// </summary>

        /// <param name="am">  </param>

        /// <param name="an">  </param>

        /// <param name="aName">    </param>

        public ABCMatrix(int am, int an, string aName)

        {

            iRow = am;

            iLine = an;

            abcMartix = new int[iRow, iLine];

            name = aName;

        }

       

        public int getM

        {

            get { return iRow; }

        }



        public int getN

        {

            get { return iLine; }

        }



        /// <summary>

        ///     

        /// </summary>

        public int[,] Members

        {

            get{return abcMartix;}

            set{abcMartix=value;}

        }



        /// <summary>

        ///      

        /// </summary>

        public string Name

        {

            get { return name; }

            set { name = value; }

        }


좋은 웹페이지 즐겨찾기