zoukankan      html  css  js  c++  java
  • c#二维数组

    c#二维数组

    2019年04月21日 05:59:46 摩贝斯塔 阅读数 592

    static void Main(string[] args)
    {
    //引出一个概念 数据容器

            //有两个下标的数组称为二维数组
    
            //二维数组定义:
    
    
            //-----------------动态初始化:------------------------------
    
            //int [,]数组名 = new   类型[常量表达式1 , 常量表达式2];
            //                          第一纬的长度    第二纬的长度
            //eg:
            //int[,] a = new int[5, 30];
            //Console.WriteLine(a[0,0]);
    
            //第一种动态初始化:
            //int[,] array = new int[2, 3] { { 1, 2, 3, }, { 4, 5, 6, } };
            //               2表示有两个对象,3表示每个对象里面有三个元素。    每个对象里面的元素数量必须一样。
            //第二种动态初始值:
            //int[,] map  = new int[ ,] { { 1, 2, 3, }, { 4, 5, 6, } };
    
            //
            //-----------------静态初始化:--------------------------------
    
            //类型[,]数组名={{具体数值1,具体数值2},{具体数值3,具体数值4}……}
            //int[,] gameMap = { { 2, 3 }, { 4, 5 } };
            //eg:
            //int[,] b = { { 95, 80, 92 }, { 1, 2, 3 }, { 4, 5, 6 } };
            //int[,] c = { { 80, 92 }, { 2, 3 }, { 5, 6 } };
    
            //二维数组的元素也称为双下标变量。
            //---------------------行列-----------------------------
            //int[,] map  = new int[ ,] { { 1, 2, 3, }, { 4, 5, 6, } };
            //等同于:
            //int[,] map  = new int[ ,] { 
            //                             { 1, 2, 3, },
            //                             { 4, 5, 6, }
            //                           };
    
    
            //-----------------------练习---------------------------
            //1、将一个二维数组的行和列交换,存储到另外一个 数组中去。
            //int[,] a = new int[2, 3] { { 1, 3, 2, }, { 4, 3, 2 } };
    
            //Console.WriteLine(a.Length);      //6个元素
            //Console.WriteLine(a.GetLength(0));//2行
            //Console.WriteLine(a.GetLength(1));//3列
    
            //int[,] b = new int[3, 2];
    
            //for (int i = 0; i < a.GetLength(0); i++)
            //{
            //    for (int j = 0; j < a.GetLength(1); j++)
            //    {
            //        b[j, i] = a[i, j];
            //        Console.WriteLine("第" + i + "行" + "------" + "第" + j + "列" + "------" + a[i, j]);
    
            //    }
            //}
    
    
            //2、有一个3行4列的二维数组,要求编程找出最大元 素,并输出所在的行和列。
            //int[,] a = new int[3, 4] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } };
    
            //int max = int.MinValue;
            //int hang = 0;
            //int lie = 0;
    
            //for (int i = 0; i < a.GetLength(0); i++)
            //{
            //    for (int j = 0; j < a.GetLength(1); j++)
            //    {
            //        if (max < a[i, j])
            //        {
            //            max = a[i, j];
            //            hang = i;
            //            lie = j;
            //        }
            //    }
            //}
            //Console.WriteLine("最大值是: " + max + "         " + "第" + hang + "行" + "------" + "第" + lie + "列");
  • 相关阅读:
    bzoj 1914: [Usaco2010 OPen]Triangle Counting 数三角形【叉积+极角排序+瞎搞】
    poj 1286 Necklace of Beads【polya定理+burnside引理】
    poj 2154 Color【polya定理+欧拉函数】
    poj 2409 Let it Bead【polya定理+burnside引理】
    bzoj 3534: [Sdoi2014]重建【矩阵树定理】
    bzoj 1774: [Usaco2009 Dec]Toll 过路费【排序+Floyd】
    bzoj 4596: [Shoi2016]黑暗前的幻想乡【容斥原理+矩阵树定理】
    bzoj 4031: [HEOI2015]小Z的房间【矩阵树定理】
    poj Find a multiple【鸽巢原理】
    bzoj Strange Way to Express Integers【excrt】
  • 原文地址:https://www.cnblogs.com/grj001/p/12224442.html
Copyright © 2011-2022 走看看