8. C# -- 一维数组,二维数组,锯齿数组

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{

    class Program
{
        static void Main(string[] args)
{
            //声明一维数组,并输出
            Console.WriteLine("ouput  array.");
            string []friendNames = {"robert","mike","jeremy" };
            int i;
            Console.WriteLine("here are {0} of my friends", friendNames.Length);
            for (i = 0; i < friendNames.Length;i++ )
{
                Console.WriteLine(friendNames[i]);
}
            Console.WriteLine("ouput double array.");
            //声明二维数组,并输出
            double[,] hillheight = { {1,2,3,4},{5,6,7,8}};
            foreach (double height in hillheight)
{
                Console.WriteLine("{0}",height);
}
            Console.WriteLine("ouput divisor array.");
            //声明锯齿数组,数组的数组
            //divisor1To10,用于保护int[]元素,而不是int元素;
            //需要对int[]元素进行遍历
            int[][] divisor1To10 = {
                                      new int []{1},
                                      new int []{1,2},
                                      new int []{1,3},
                                      new int []{1,2,4},
                                      new int []{1,5},
                                      new int []{1,2,3,6},
                                      new int []{1,7},
                                      new int []{1,2,4,8},
                                      new int []{1,3,9},
                                      new int []{1,2,5,10}
};
            foreach (int[] divisorOfInt in divisor1To10)
{
                foreach (int divisor in divisorOfInt)
{
                    Console.WriteLine(divisor);
}
}
            Console.ReadLine();
 
}
}
}
时间: 2024-07-29 14:13:46

8. C# -- 一维数组,二维数组,锯齿数组的相关文章

C语言malloc函数为一维,二维,三维数组分配空间

c语言允许建立内存动态分配区域,以存放一些临时用的数据,这些数据不必在程序的声明部分定义,也不必等到函数结束时才释放,而是需要时随时开辟,不需要时随时释放,这些数据存储在堆区.可以根据需要,向系统申请所取空间的大小,因为没有在声明部分定义它们为变量或数组,所以不能通过变量名或数组的方式去引用这些数据,只能通过指针来引用. 对内存的动态分配是通过系统提供的库函数来实现的,主要有malloc,calloc,free,realloc这四个函数. 接下来写一下malloc函数如何实现为一维,二维,三维数

树状数组 / 二维树状数组

一维树状数组 · 单点修改 + 单点查询: 直接使用即可 · 区间修改 + 单点查询: 另外维护一个维护前缀和的树状数组,查询时查询与原值相加即可. · 区间修改 + 区间查询: <div align=center> 居中 </div> 原文地址:https://www.cnblogs.com/Colythme/p/9853159.html

一维 + 二维树状数组 + 单点更新 + 区间更新 详解

树状数组详解: 假设一维数组为A[i](i=1,2,...n),则与它对应的树状数组C[i](i=1,2,...n)是这样定义的: C1 = A1 C2 = A1 + A2 C3 = A3 C4 = A1 + A2 + A3 + A4 C5 = A5 C6 = A5 + A6 ................. C8 = A1 + A2 + A3 + A4 + A5 + A6 + A7 + A8 ................ 如图可知: 为奇数的时候他是代表他本身,而为偶数的时候则是代表着自

C++ 一维数组 二维数组 指针

1.int a[3] = {1, 2, 3}a代表数组的首地址&a[0]也是数组的首地址 2.// int a[2][2] = {0, 1, 2, 3}; // **a 就是 a[0][0] 第一行第一列.// *(*a + 1) 就是 a[0][1] 第一行第二列.// **(a + 1) 就是 a[1][0] 第二行第一列.// *(*(a + 1) + 1) 就是 a[1][1] 第二行第二列. 3.int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9

POJ 1195 Mobile phones(二维树状数组)

题目链接:POJ 1195 题意: 给出一个S*S的矩阵(行.列号从1开始),每个元素初始值为0,有两种操作:一种是第X行第Y列元素值加A:另一种是查询给定范围矩阵的所有元素之和(L<=X<=R,B<=Y<=T). 分析: 查询给定范围矩阵的所有元素之和是二维区间和,可以转换为二维前缀和求值.类比一维前缀和求法,二维区间和S(L, B, R, T) = S(1, 1, R, T) - S(1 ,1, L-1, T) - S(1, 1, R, B-1) + S(1, 1, L-1,

POJ 2155 Matrix(二维树状数组,绝对具体)

Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20599   Accepted: 7673 Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1

二维树状数组(水题) POJ1195

前段时间遇到线段树过不了,树状数组却过了的题.(其实线段树过得了的) 回忆了下树状数组. 主要原理,还是二进制位数,每一项的和表示其为它的前((最后一位1及其后)的二进制数)和,可从二进制图来看.(用线段树想一想其实只是线段树编号不同而已,本质类似) 写了下二维树状数组,几乎和一维相同,也没必要不同. #include <cstdio> #include <cstring> int l,r,x,y,n,a,p,sum[1125][1125]; inline int lowbit(i

[poj2155]Matrix(二维树状数组)

Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1

POJ 2155 Matrix(二维树状数组,绝对详细)

Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20599   Accepted: 7673 Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1

POJ 1195 Mobile phones (二维树状数组)

Description Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows and columns numbered from 0 to S-1. Each square contain