zoukankan      html  css  js  c++  java
  • 如何比较两个二维数组是否相等

    一句话: 用 CompareMem 对比内存即可.


    {对比静态数组}
    procedure TForm1.Button1Click(Sender: TObject);
    var
      arr1: array[0..3] of AnsiChar;
      arr2: array[0..3] of Byte;
    begin
      arr1[0] := 'A'; arr1[1] := 'B'; arr1[2] := 'C'; arr1[3] := 'D';
      arr2[0] := 65;  arr2[1] := 66;  arr2[2] := 67;  arr2[3] := 68;
    
      if CompareMem(@arr1, @arr2, SizeOf(arr1)) then
        ShowMessage('arr1 与 arr2 中的数据相同');
    end;
    
    {对比动态数组}
    procedure TForm1.Button2Click(Sender: TObject);
    var
      arr1: array of AnsiChar;
      arr2: array of Byte;
    begin
      SetLength(arr1, 4);
      SetLength(arr2, 4);
      arr1[0] := 'A'; arr1[1] := 'B'; arr1[2] := 'C'; arr1[3] := 'D';
      arr2[0] := 65;  arr2[1] := 66;  arr2[2] := 67;  arr2[3] := 68;
    
      if CompareMem(arr1, arr2, SizeOf(arr1)) then
        ShowMessage('arr1 与 arr2 中的数据相同');
    end;
    
    {多维数组也一样}
    procedure TForm1.Button3Click(Sender: TObject);
    var
      arr1: array[0..1, 0..1] of AnsiChar;
      arr2: array[0..1, 0..1] of Byte;
    begin
      arr1[0,0] := 'A'; arr1[0,1] := 'B'; arr1[1,0] := 'C'; arr1[1,1] := 'D';
      arr2[0,0] := 65;  arr2[0,1] := 66;  arr2[1,0] := 67;  arr2[1,1] := 68;
    
      if CompareMem(@arr1, @arr2, SizeOf(arr1)) then
        ShowMessage('arr1 与 arr2 中的数据相同');
    end;
  • 相关阅读:
    POJ 2723 Get Luffy Out(2-SAT)
    ZOJ 3613 Wormhole Transport
    HDU 4085 Peach Blossom Spring
    NBUT 1221 Intermediary
    NBUT 1223 Friends number
    NBUT 1220 SPY
    NBUT 1218 You are my brother
    PAT 1131. Subway Map (30)
    ZSTU OJ 4273 玩具
    ZSTU OJ 4272 最佳淘汰算法
  • 原文地址:https://www.cnblogs.com/h2zZhou/p/11435210.html
Copyright © 2011-2022 走看看