• c#笔记(六)——数组(2)


    //将一个二维数组的行和列交换,存储到另外一个数组中
                //int[,] a = new int[2, 3] { { 1, 2 ,3},{ 4, 5, 6 } };
               // int[,] b = new int[a.GetLength(1), a.GetLength(0)];
               // for (int i = 0; i < b.GetLength(0); i++)
               // {
               //     for (int j = 0; j < b.GetLength(1); j++)
               //     {
               //         b[i, j] = a[j, i];
               //         Console.Write(b[i,j]+" ");
               //     }
               //     Console.WriteLine();
               //}
    //有个3行4列的二维数组,求最大元素以及所在的行和列
                //int[,] a = new int[3, 4] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } };
                //int max, row, line;
                //max = a[0,0];
                //row = 0;
                //line = 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];
                //            row = i;
                //            line = j;
                //        }
                //    }
                //}
                //Console.WriteLine("max={0},行号是{1},列号是{2}", max, row+1, line+1);
               赋值一个二维数组
    //int[,] a = new int[4, 3];
                //for (int i = 0; i < a.GetLength(0); i++)
                //{
                //    Console.WriteLine("请输入第{0}行赋值的数",i);
                //    for (int j = 0; j < a.GetLength(1); j++)
                //    {
                //        a[i, j] = int.Parse(Console.ReadLine());
                //    }
     
                //}
                //Console.ReadKey();
                ////打印数组
                //Console.WriteLine("打印赋值的数组");
                //for (int i = 0; i < a.GetLength(0); i++)
                //{
                //    for (int j = 0; j < a.GetLength(1); j++)
                //    {
                //        Console.Write(a[i, j] + " ");
                //    }
                //    Console.WriteLine();
                //}
     
                //Console.WriteLine("第一行元素");
                //for (int i = 0; i < a.GetLength(1); i++)
                //{
                //    Console.Write(a[0, i] + " ");
                //}
                //Console.WriteLine("和");
                //int sum = 0;
                //for (int i = 0; i < a.GetLength(1); i++)
                //{
                //    sum += a[1, i];
                //}
                //Console.WriteLine("sum=" + sum);
  • 相关阅读:
    8.10
    今日头条笔试题 1~n的每个数,按字典序排完序后,第m个数是什么?
    Gym 100500B Conference Room(最小表示法,哈希)
    CodeForces 438D The Child and Sequence(线段树)
    UVALIVE 6905 Two Yachts(最小费用最大流)
    Gym Conference Room (最小表示法,哈希)
    hdu 2389 Rain on your Parade(二分图HK算法)
    Codeforces Fox And Dinner(最大流)
    zoj 3367 Counterfeit Money(dp)
    ZOJ3370. Radio Waves(2-sat)
  • 原文地址:https://www.cnblogs.com/ningyongbin/p/5922151.html
Copyright © 2020-2023  润新知